forked from n9e/plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
10_ss.sh
executable file
·61 lines (57 loc) · 1.79 KB
/
10_ss.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/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}')
localip=$(ifconfig `route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|head -n 1)
step=$(basename $0|awk -F'_' '{print $1}')
timestamp=$(date +%s)
echo '[
{
"endpoint": "'${localip}'",
"tags": "",
"timestamp": '${timestamp}',
"metric": "net.ss.estab",
"value": '${ss_estab}',
"step": '${step}'
},
{
"endpoint": "'${localip}'",
"tags": "",
"timestamp": '${timestamp}',
"metric": "net.ss.closed",
"value": '${ss_closed}',
"step": '${step}'
},
{
"endpoint": "'${localip}'",
"tags": "",
"timestamp": '${timestamp}',
"metric": "net.ss.orphaned",
"value": '${ss_orphaned}',
"step": '${step}'
},
{
"endpoint": "'${localip}'",
"tags": "",
"timestamp": '${timestamp}',
"metric": "net.ss.synrecv",
"value": '${ss_synrecv}',
"step": '${step}'
},
{
"endpoint": "'${localip}'",
"tags": "",
"timestamp": '${timestamp}',
"metric": "net.ss.timewait",
"value": '${ss_timewait}',
"step": '${step}'
}
]'