Cacti
目标根据/proc/net/sockstat创建针对服务器sockstat的状态Cacti图形
目标探索
# cat /proc/net/sockstat
sockets: used 6121
TCP: inuse 6142 orphan 0 tw 63905 alloc 6145 mem 4206
UDP: inuse 6 mem 3
UDPLITE: inuse 0
RAW: inuse 0
FRAG: inuse 0 memory 0
#
提取有价值目标
socketsUsed
tcpInuse
tcpOrphan
tcpTw
tcpAlloc
tcpMem
Client
部署脚本
#!/bin/bash
#Filepath: /usr/local/nagios/libexec/check_sockstat
#socketsUsed
#tcpInuse
#tcpOrphan
#tcpTw
#tcpAlloc
#tcpMem
#
#sockets: used 6121
#TCP: inuse 6142 orphan 0 tw 63905 alloc 6145 mem 4206
#UDP: inuse 6 mem 3
#UDPLITE: inuse 0
#RAW: inuse 0
#FRAG: inuse 0 memory 0
##
#
#
#echo "OK"
#echo $1
if [ $1 = "socketsUsed" ];then
name="socketsUsed"
result=`cat /proc/net/sockstat | grep sockets | awk '{print $3}'`
fi
if [ $1 = "tcpInuse" ];then
name="tcpInuse"
result=`cat /proc/net/sockstat | grep TCP | awk '{print $3}'`
fi
if [ $1 = "tcpOrphan" ];then
name="tcpOrphan"
result=`cat /proc/net/sockstat | grep TCP | awk '{print $5}'`
fi
if [ $1 = "tcpTw" ];then
name="tcpTw"
result=`cat /proc/net/sockstat | grep TCP | awk '{print $7}'`
fi
if [ $1 = "tcpAlloc" ];then
name="tcpAlloc"
result=`cat /proc/net/sockstat | grep TCP | awk '{print $9}'`
fi
if [ $1 = "tcpMem" ];then
name="tcpMem"
result=`cat /proc/net/sockstat | grep TCP | awk '{print $11}'`
fi
echo "$name:$result"
测试结果
# ./check_sockstat socketsUsed
socketsUsed:5655
# ./check_sockstat tcpInuse
tcpInuse:5694
# ./check_sockstat tcpOrphan
tcpOrphan:0
# ./check_sockstat tcpTw
tcpTw:64047
# ./check_sockstat tcpAlloc
tcpAlloc:5716
# ./check_sockstat tcpMem
tcpMem:2257
设置nrpe命令
command=/usr/local/nagios/libexec/check_sockstat $ARG1$
本地测试
# /usr/local/nagios/libexec/check_sockstat tcpInuse
tcpInuse:5704
远程测试
# /usr/local/nagios/libexec/check_nrpe -H 10.125.89.135 -c cacti_sockstat -a tcpInuse
tcpInuse:5704
Cacti
data input method
data template
graph template
命令行部署
#!/bin/bash
ip=$1
# 判断是否存在,如果存在就退出
hostfind=`php add_graphs.php --list-hosts | grep $ip$ | wc -l`
[ $hostfind -eq 1 ] && ( echo "host $ip 已经存在 ";exit 0 )
# 添加hosts
php add_device.php --description=$ip --ip=$ip --template=9
hostid=`php add_graphs.php --list-hosts | grep $ip$ | awk '{print $1}'`
echo $hostid
#exit 0
#[[ $hostid -gt 70 ]] || exit 0
# 开始画vmstat
php add_graphs.php --graph-type=cg --graph-template-id=76 --host-id=$hostid --input-fields="server_addr=$ip"
页:
[1]