赞
踩
环境: Linux 主机
步骤: 1,在linux 主机上写个脚本执行查询当前tcp 连接的参数输出到相应值得文本中
2,建立个任务计划,每分钟执行一次
3, Linux 主机上的 zabbix 客户端配置文件定义好自定义key
1, 在/home/zabbix/sh/ 建立一个tcpconnection 目录,建立一个net.py 脚本,内容在文章最底下贴出
2,建立任务计划
*/1 * * * * /usr/bin/python2.6 /home/zabbix/sh/tcpconnection/net.py
3,配置Linux 主机上面的zabbix 客户端配置文件zabbix_agentd.conf
UserParameter=SYN_RECV,/bin/cat /home/zabbix/sh/tcpconnection/SYN_RECV
UserParameter=ESTABLISHED,/bin/cat /home/zabbix/sh/tcpconnection/ESTABLISHED
UserParameter=FIN_WAIT1,/bin/cat /home/zabbix/sh/tcpconnection/FIN_WAIT1
UserParameter=FIN_WAIT2,/bin/cat /home/zabbix/sh/tcpconnection/FIN_WAIT2
UserParameter=TIME_WAIT,/bin/cat /home/zabbix/sh/tcpconnection/TIME_WAIT
4,重启zabbix_agentd 服务
/etc/init.d/zabbix_agentd restart
5,net.py 脚本内容
#!/usr/bin/env python
import os
def main():
data = get_data()
SYN_RECV = data.count('SYN_RECV')
ESTABLISHED = data.count('ESTABLISHED')
FIN_WAIT1 = data.count('FIN_WAIT1')
FIN_WAIT2 = data.count('FIN_WAIT2')
TIME_WAIT = data.count('TIME_WAIT')
http = data.count('80')
https = data.count('440')
write_file('SYN_RECV', SYN_RECV)
write_file('ESTABLISHED', ESTABLISHED)
write_file('FIN_WAIT1', FIN_WAIT1)
write_file('FIN_WAIT2', FIN_WAIT2)
write_file('TIME_WAIT', TIME_WAIT)
write_file('http', http)
write_file('https', https)
print 'ESTABLISHED', ESTABLISHED
print 'SYN_RECV', SYN_RECV
print 'FIN_WAIT1', FIN_WAIT1
print 'FIN_WAIT2', FIN_WAIT2
print 'TIME_WAIT', TIME_WAIT
print 'http', http
print 'https', https
def get_data():
a = os.popen('netstat -an')
data = a.read()
return data
def write_file(filename, value):
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
f=open('%s/%s' %(BASE_DIR, filename),"w")
f.write(str(value))
f.close()
if __name__ == '__main__':
main()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。