赞
踩
一、在被监控端上设置
主要命令:
1
|
netstat
-
an
|
awk
'/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
|
输出内容:
TIME_WAIT 100
CLOSE_WAIT 5
FIN_WAIT1 6
ESTABLISHED 161
SYN_RECV 1
LAST_ACK 1
LISTEN 11
下面以监控TIME_WAIT的数量为例子(先来准备下脚本)
1
2
3
4
5
|
mkdir
-
pv
/
usr
/
local
/
shell
/
zabbix
cd
/
usr
/
local
/
shell
/
zabbix
vim
tcp_connections
.
sh
|
1
2
3
4
|
#!/bin/bash
netstat
-
an
|
awk
'/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
|
grep
$
1
|
cut
-
d’ ‘
-
f2
//脚本依赖上面的主要命令
|
在zabbix_server被监控的节点上编辑zabbix的配置文件
1
|
vim
/
usr
/
local
/
zabbix
/
etc
/
zabbix_agentd
.
conf
|
#在256行添加下列内容
UnsafeUserParameters=1
#在265行添加以下内容
UserParameter=TIME_WAIT,/bin/bash /usr/local/shell/zabbix/tcp_connections.sh TIME_WAIT
重启客户端
1
|
service
zabbix_agentd
restart
|
二、zabbix_server 端设置
首先看是否能否取到值
1
2
3
|
cd
/
usr
/
local
/
zabbix
/
bin
.
/
zabbix_get
-
s
10.6.5.1
-
k
TIME_WAIT
|
如果能获取到数值,那么恭喜你成功了。
访问zabbix web界面,创建模板
建图形
将模板应用到对应的机器上,绘图结果如下:
#!/bin/bash
sed -i "s#\# UnsafeUserParameters=0#UnsafeUserParameters=1#g" /usr/local/etc/zabbix_agentd.conf
echo "Include=/usr/local/etc/zabbix_agentd.conf.d/" >>/usr/local/etc/zabbix_agentd.conf
mkdir -p /usr/local/shell/zabbix
cat << EOF >/usr/local/shell/zabbix/tcp_connections.sh
#!/bin/bash
netstat -an |awk '/^tcp/ {++S[\$NF]} END {for(a in S) print a, S[a]}'|grep \$1|cut -d' ' -f2
EOF
cat << EOF >/usr/local/shell/zabbix/zabbix_tcp.sh
#!/bin/bash
netstat -s|grep "connections established"|awk '{print\$1}'
EOF
chmod 755 /usr/local/shell/zabbix/zabbix_tcp.sh
mkdir -p /usr/local/etc/zabbix_agentd.conf.d
cat << EOF >/usr/local/etc/zabbix_agentd.conf.d/tcp
#!monitor tcp
UserParameter=TIME_WAIT,/bin/bash /usr/local/shell/zabbix/tcp_connections.sh TIME_WAIT
UserParameter=CLOSE_WAIT,/bin/bash /usr/local/shell/zabbix/tcp_connections.sh CLOSE_WAIT
UserParameter=ESTABLISHED,/bin/bash /usr/local/shell/zabbix/tcp_connections.sh ESTABLISHED
UserParameter=FIN_WAIT1,/bin/bash /usr/local/shell/zabbix/tcp_connections.sh FIN_WAIT1
UserParameter=LAST_ACK,/bin/bash /usr/local/shell/zabbix/tcp_connections.sh LAST_ACK
UserParameter=LISTEN,/bin/bash /usr/local/shell/zabbix/tcp_connections.sh LISTEN
UserParameter=SYN_RECV,/bin/bash /usr/local/shell/zabbix/tcp_connections.sh SYN_RECV
UserParameter=tcpconnect,/usr/local/shell/zabbix/zabbix_tcp.sh
EOF
service zabbix_agentd restart
几个监控项的键值就是TIME_WAIT、CLOSE_WAIT、ESTABLISHED、FIN_WAIT1、LAST_ACK、LISTEN、SYN_RECV、tcpconnect
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。