Commit 8c233123 by feilong

init

parent eeee7aa7
#!/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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment