概述
今天主要是导师说要用zabbix监控下TCP连接情况,所以顺便整理了这篇文章,下面一起来看看吧!
一、获取监控数据
netstat -an|awk '/^tcp/{++S[$NF]}END{for(a in S) print a,S[a]}'
TCP各监控状态描述
二、zabbix客户端配置监控脚本
1、编写脚本
# cat /etc/zabbix/zabbix_agentd.d/tcp_conn_status.sh ================================================================================================#!/bin/bash#this script is used to get tcp and udp connetion status#tcp statusmetric=$1tmp_file=/tmp/tcp_status.txt/bin/netstat -an|awk '/^tcp/{++S[$NF]}END{for(a in S) print a,S[a]}' > $tmp_file case $metric in closed) output=$(awk '/CLOSED/{print $2}' $tmp_file) if [ "$output" == "" ];then echo 0 else echo $output fi ;; listen) output=$(awk '/LISTEN/{print $2}' $tmp_file) if [ "$output" == "" ];then echo 0 else echo $output fi ;; synrecv) output=$(awk '/SYN_RECV/{print $2}' $tmp_file) if [ "$output" == "" ];then echo 0 else echo $output fi ;; synsent) output=$(awk '/SYN_SENT/{print $2}' $tmp_file) if [ "$output" == "" ];then echo 0 else echo $output fi ;; established) output=$(awk '/ESTABLISHED/{print $2}' $tmp_file) if [ "$output" == "" ];then echo 0 else echo $output fi ;; timewait) output=$(awk '/TIME_WAIT/{print $2}' $tmp_file) if [ "$output" == "" ];then echo 0 else echo $output fi ;; closing) output=$(awk '/CLOSING/{print $2}' $tmp_file) if [ "$output" == "" ];then echo 0 else echo $output fi ;; closewait) output=$(awk '/CLOSE_WAIT/{print $2}' $tmp_file) if [ "$output" == "" ];then echo 0 else echo $output fi ;; lastack) output=$(awk '/LAST_ACK/{print $2}' $tmp_file) if [ "$output" == "" ];then echo 0 else echo $output fi ;; finwait1) output=$(awk '/FIN_WAIT1/{print $2}' $tmp_file) if [ "$output" == "" ];then echo 0 else echo $output fi ;; finwait2) output=$(awk '/FIN_WAIT2/{print $2}' $tmp_file) if [ "$output" == "" ];then echo 0 else echo $output fi ;; *) echo -e "e[033mUsage: sh $0 [closed|closing|closewait|synrecv|synsent|finwait1|finwait2|listen|established|lastack|timewait]e[0m"esac================================================================================================
2、添加自定义参数
# cat /etc/zabbix/zabbix_agentd.d/tcp.conf================================================================================================UserParameter=tcp.status[*],/etc/zabbix/zabbix_agentd.d/tcp_conn_status.sh $1================================================================================================
3、授权
chown -R zabbix:zabbix /etc/zabbixchmod -R 755 /etc/zabbix
4、重启客户端
systemctl restart zabbix-agent
5、在zabbix服务端测试
bbix_get -s 172.26.150.134 -p 10050 -k tcp.status[listen]
三、导入zabbix模板文件
1、下载模板
模板名为:tcp_export_templates.xml,内容如下:
2、导入模板
配置-模板-导入
3、模板/主机链接模板
四、查看图形
监测-图形
模板领取方式
这份TCP模板怎么领取呢?
1.请在评论区评论+点赞+转发
2.点击关注,关注本头条号
3.进入头条号主页面,右上角有私信功能,私信小编:tcp模板
同时希望大家多多转发分享给更多的朋友哦!