当前位置: > Linux服务器 > 监控工具 >

使用rrdtool监控tcp状态一例

时间:2014-10-26 01:08来源:linux.it.net.cn 作者:it

以前写的rrdtool 监控tcp状态的脚本

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

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


netstat -an |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

 

(责任编辑:IT)
------分隔线----------------------------