使用rrdtool监控tcp状态一例

发布时间:2019-10-18编辑:脚本学堂
rrdtool 监控tcp状态的脚本,分享给大家,感兴趣的朋友可以参考下。

以前写的rrdtool 监控tcp状态的脚本,分享给大家,感兴趣的朋友可以参考下。

复制代码 代码如下:
#!/bin/bash
set -x

path=/data/rrdtool
rrd=/usr/local/rrdtool/bin/rrdtool
rrdtime=`date -d '1 days ago' +%s`


netstat -an |linuxjishu/13830.html target=_blank class=infotextkey>awk '/^tcp/{a[$NF]++}END{for (b in a )print b"="a[b]}' > /tmp/rrdtcp.sh
chmod  a+x  /tmp/rrdtcp.sh
source /tmp/rrdtcp.sh
echo $ESTABLISHED
rm -f  /tmp/rrdtcp.sh

update  ()
{
$rrd  updatev ${path}/tcp.rrd  N:${ESTABLISHED}:${TIME_WAIT}:${SYN_RECV}:${LAST_ACK}:${FIN_WAIT1}:${FIN_WAIT2}:${CLOSING}:${SYN_SENT}
}

if  [ -e "${path}/tcp.rrd"  ]
then
   echo 'rrdfile is ok'   >/dev/null 2>&1
   sleep 1
else
$rrd create ${path}/tcp.rrd  --start $rrdtime
--step 300
DS:ESTABLISHED:GAUGE:600:0:10000
DS:TIME_WAIT:GAUGE:600:0:10000
DS:SYN_RECV:GAUGE:600:0:10000
DS:LAST_ACK:GAUGE:600:0:10000
DS:FIN_WAIT1:GAUGE:600:0:10000
DS:FIN_WAIT2:GAUGE:600:0:10000
DS:CLOSING:GAUGE:600:0:10000
DS:SYN_SENT:GAUGE:600:0:10000
RRA:MAX:0.5:1:600
RRA:MAX:0.5:4:600
RRA:MAX:0.5:24:600
RRA:MAX:0.5:288:730

fi

update