zabbix (11) 监控TCP连接数
对TCP的监控可以采用ss、netstat、/proc/net/tcp这三个不同的方案来实现。其中ss是最快的
(1)ss命令
[root@manager1 script_py ::]#time ss state all|awk '{++S[$2]} END{for( i in S) {printf "%-11s %s\n",i,S[i]} }'
LISTEN
ESTAB
State
TIME-WAIT
UNCONN real 0m0.036s
user 0m0.024s
sys 0m0.011s
(2)netstat命令
[root@manager1 script_py ::]#time netstat -an |awk '/^tcp/{++S[$NF]}END{for(i in S){printf "%-11s %s\n",i,S[i]}}'
LISTEN
ESTABLISHED
TIME_WAIT real 0m0.007s
user 0m0.005s
sys 0m0.002s
(3)读取/proc/net/tcp 文件,其中第四列为TCP连接的各个状态,如:
[root@manager1 script_py ::]#cat /proc/net/tcp|awk '{++S[$4]} END{for( i in S) {printf "%-11s %s\n",i,S[i]} }' 0A
st
第四列各个状态的意思如下:
00 "ERROR_STATYS",
01 "TCP_ESTABLISHED"
02 "TCP_SYN_SENT"
03 "TCP_SYN_RECV"
04 "TCP_FIN_WAIT1"
05 "TCP_FIN_WAIT2"
06 "TCP_TIME_WAIT"
07 "TCP_CLOSE"
08 "TCP_CLOSE_WAIT"
0A "TCP_LISTEN"
0B "TCP_CLOSING"
添加自定义键:
[root@manager1 script_py ::]#cat /etc/zabbix/zabbix_agentd.d/tcp_connection.conf
UserParameter=tcp_connection.errorstatus,awk '($4=="00"){print $4}' /proc/net/tcp|awk '{++S[$1]}END {for(i in S){print S[i]}}'
UserParameter=tcp_connection.established,awk '($4=="01"){print $4}' /proc/net/tcp|awk '{++S[$1]}END {for(i in S){print S[i]}}'
UserParameter=tcp_connection.synsent,awk '($4=="02"){print $4}' /proc/net/tcp|awk '{++S[$1]}END {for(i in S){print S[i]}}'
UserParameter=tcp_connection.synrecv,awk '($4=="03"){print $4}' /proc/net/tcp|awk '{++S[$1]}END {for(i in S){print S[i]}}'
UserParameter=tcp_connection.finwait1,awk '($4=="04"){print $4}' /proc/net/tcp|awk '{++S[$1]}END {for(i in S){print S[i]}}'
UserParameter=tcp_connection.finwait2,awk '($4=="05"){print $4}' /proc/net/tcp|awk '{++S[$1]}END {for(i in S){print S[i]}}'
UserParameter=tcp_connection.timewait,awk '($4=="06"){print $4}' /proc/net/tcp|awk '{++S[$1]}END {for(i in S){print S[i]}}'
UserParameter=tcp_connection.close,awk '($4=="07"){print $4}' /proc/net/tcp|awk '{++S[$1]}END {for(i in S){print S[i]}}'
UserParameter=tcp_connection.close_wait,awk '($4=="08"){print $4}' /proc/net/tcp|awk '{++S[$1]}END {for(i in S){print S[i]}}'
UserParameter=tcp_connection.last_ack,awk '($4=="09"){print $4}' /proc/net/tcp|awk '{++S[$1]}END {for(i in S){print S[i]}}'
UserParameter=tcp_connection.listen,awk '($4=="0A"){print $4}' /proc/net/tcp|awk '{++S[$1]}END {for(i in S){print S[i]}}'
UserParameter=tcp_connection.closing,awk '($4=="0B"){print $4}' /proc/net/tcp|awk '{++S[$1]}END {for(i in S){print S[i]}}'
最新文章
- linux下打包工具
- Android基于mAppWidget实现手绘地图(四)--如何附加javadoc
- Spring+Struts2+Mybatis框架搭建时的常见典型问题
- .NET之特性和属性
- 解决hexo神烦的DTraceProviderBindings MODULE_NOT_FOUND
- a href=";javascript:void(0)"; 是什么意思?加不加上有什么区别?
- 关于Set<;Long>;Map<;Long,String>;的一些小注意事项 自动转换类型
- 一类SG函数递推性质的深入分析——2018ACM陕西邀请赛H题
- 观察者模式 Observer 发布订阅模式 源 监听 行为型 设计模式(二十三)
- 面向对象—的__new__()方法详解
- NET Core微服务之路:SkyWalking+SkyApm-dotnet分布式链路追踪系统的分享
- 强制禁用gitlab的双因子认证:Two-Factor Authentication
- linux----CenterOS7中在线安装jdk
- oracle数据类型及其隐式转换
- access建立sql查询语句运行查询语句
- No member named &#39;setResizeMode&#39; in &#39;QHeaderView&#39; - Convert Qt 4.7 to Qt 5.8
- P2213 [USACO14MAR]懒惰的牛The Lazy Cow_Sliver
- Unity Lighting - Choosing a Rendering Path 选择渲染路径(三)
- css3动画效果:2 简易动画
- Javascript 基础汇总
热门文章
- windows下搭建nginx负载均衡
- python之函数基本使用
- C语言中参数的传递
- js中的深复制与浅复制
- RuntimeWarning: DateTimeField AppToken.expire_date received a naive datetime (2019-05-16 16:54:01.144582) while time zone support is active. RuntimeWarning)
- SecureCRT和SecureFX的安装和破解
- 记录java+testng运行selenium(二)---定义元素类及浏览器
- 如何11 周打造全能Python工程师!
- Linux命令——lsb_release
- Linux VPS搭建蚂蚁笔记Leanote私有云笔记存储平台