Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
op
plugin
Commits
8c233123
Commit
8c233123
authored
May 15, 2020
by
feilong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
eeee7aa7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
10_ss.sh
10_ss.sh
+62
-0
No files found.
10_ss.sh
0 → 100755
View file @
8c233123
#!/bin/bash
#
# socket的统计信息,还是蛮有用的,故而写一个插件来采集
# 不同的系统版本,输出未必一样,大家用的时候要注意测试
#
# TCP: 360 (estab 272, closed 71, orphaned 0, synrecv 0, timewait 71/0), ports 0
output
=
$(
ss
-s
|
grep
TCP:
)
ss_estab
=
$(
echo
$output
|
grep
-Po
"estab (
\d
+)"
| awk
'{print $2}'
)
ss_closed
=
$(
echo
$output
|
grep
-Po
"closed (
\d
+)"
| awk
'{print $2}'
)
ss_orphaned
=
$(
echo
$output
|
grep
-Po
"orphaned (
\d
+)"
| awk
'{print $2}'
)
ss_synrecv
=
$(
echo
$output
|
grep
-Po
"synrecv (
\d
+)"
| awk
'{print $2}'
)
ss_timewait
=
$(
echo
$output
|
grep
-Po
"timewait (
\d
+)"
| awk
'{print $2}'
)
endpoint
=
$(
ifconfig
`
route|grep
'^default'
|awk
'{print $NF}'
`
|grep inet|awk
'{print $2}'
|awk
-F
':'
'{print $NF}'
|head
-n
1
)
step
=
$(
basename
$0
|awk
-F
'_'
'{print $1}'
)
timestamp
=
$(
date +%s
)
echo
'[
{
"endpoint": "'
${
endpoint
}
'",
"tags": "",
"timestamp": '
${
timestamp
}
',
"metric": "net.ss.estab",
"value": '
${
ss_estab
}
',
"step": '
${
step
}
'
},
{
"endpoint": "'
${
endpoint
}
'",
"tags": "",
"timestamp": '
${
timestamp
}
',
"metric": "net.ss.closed",
"value": '
${
ss_closed
}
',
"step": '
${
step
}
'
},
{
"endpoint": "'
${
endpoint
}
'",
"tags": "",
"timestamp": '
${
timestamp
}
',
"metric": "net.ss.orphaned",
"value": '
${
ss_orphaned
}
',
"step": '
${
step
}
'
},
{
"endpoint": "'
${
endpoint
}
'",
"tags": "",
"timestamp": '
${
timestamp
}
',
"metric": "net.ss.synrecv",
"value": '
${
ss_synrecv
}
',
"step": '
${
step
}
'
},
{
"endpoint": "'
${
endpoint
}
'",
"tags": "",
"timestamp": '
${
timestamp
}
',
"metric": "net.ss.timewait",
"value": '
${
ss_timewait
}
',
"step": '
${
step
}
'
}
]'
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment