Cacti - SOCKSTAT

简介

在linux的监控中, 在TCP方面,有一个很重要的文件,叫/proc/net/sockstat,里面的内容如下:

sockets: used 150
TCP: inuse 10 orphan 0 tw 48175 alloc 12 mem 2
UDP: inuse 8 mem 2
UDPLITE: inuse 0
RAW: inuse 0
FRAG: inuse 0 memory 0

一般来说,主要关心TCP的相关数量,于是想办法把图形画出来.

框架

这里写图片描述

10.180.92.195里面的操作

data input methods

这里写图片描述

<path_cacti>/scripts/check_nrpe -H <server_addr> -c cacti_sockstat -a tcpInuse
<path_cacti>/scripts/check_nrpe -H <server_addr> -c cacti_sockstat -a socketUsed
<path_cacti>/scripts/check_nrpe -H <server_addr> -c cacti_sockstat -a tcpOrphan
<path_cacti>/scripts/check_nrpe -H <server_addr> -c cacti_sockstat -a tcpTw
<path_cacti>/scripts/check_nrpe -H <server_addr> -c cacti_sockstat -a tcpAlloc
<path_cacti>/scripts/check_nrpe -H <server_addr> -c cacti_sockstat -a tcpMem

data template

这里写图片描述

graph template

这里写图片描述

cli deploy command

#!/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"
php add_graphs.php --graph-type=cg --graph-template-id=80 --host-id=$hostid --input-fields="server_addr=$ip"
php add_graphs.php --graph-type=cg --graph-template-id=83 --host-id=$hostid --input-fields="server_addr=$ip"
php add_graphs.php --graph-type=cg --graph-template-id=84 --host-id=$hostid --input-fields="server_addr=$ip"
php add_graphs.php --graph-type=cg --graph-template-id=81 --host-id=$hostid --input-fields="server_addr=$ip"
php add_graphs.php --graph-type=cg --graph-template-id=82 --host-id=$hostid --input-fields="server_addr=$ip"

10.125.89.135里面的操作

define a command cacti_sockstat

command[cacti_sockstat]=/usr/local/nagios/libexec/check_sockstat $ARG1$

/usr/local/nagios/libexec/check_sockstat

#!/bin/bash
#  
#  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
#  [root@10-125-89-135 ~]# 
#  
#  

#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"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值