zabbix-自定义监控脚本监控TCP连接数据

1.agent端监控脚本

[root@test-agent zabbix_agentd.d]# pwd
/etc/zabbix/zabbix_agentd.d
[root@test-agent zabbix_agentd.d]# vim tcp_status_monitoring_port.sh
#!/bin/bash
#
#********************************************************************
#Author:        fengshengli
#Date:             2021-01-11
#param1            CLOSE-WAIT ESTAB LISTEN TIME-WAIT
#param2           server-port
#********************************************************************
TCPS1=$1
TCPP1=$2
export TCPS1
export TCPP1
#  切记双斜杠转义符,将awk的参数转义
TCP_NUM=`ss -ant|awk  " \\$4 ~ /:$TCPP1$/ && \\$1 ~ /^$TCPS1/ {print \\$1 \\$4 }" | wc -l `
echo $TCP_NUM

2.配置zabbix-agent配置文件

[root@test-agent zabbix_agentd.d]# vim /etc/zabbix/zabbix_agentd.conf

### Option: UnsafeUserParameters
#       Allow all characters to be passed in arguments to user-defined parameters.
#       The following characters are not allowed:
#       \ ' " ` * ? [ ] { } ~ $ ! & ; ( ) < > | # @
#       Additionally, newline characters are not allowed.
#       0 - do not allow
#       1 - allow
#
# Mandatory: no
# Range: 0-1
# Default:
# UnsafeUserParameters=0
UnsafeUserParameters=1

### Option: UserParameter
#       User-defined parameter to monitor. There can be several user-defined parameters.
#       Format: UserParameter=<key>,<shell command>
#       See 'zabbix_agentd' directory for examples.
#
# Mandatory: no
# Default:
# UserParameter=
# 服务TCP连接数监控  参数一   状态   参数二  端口
UserParameter=tcp.status.count[*],"/etc/zabbix/zabbix_agentd.d/tcp_status_monitoring_port.sh" $1 $2

3.agent端测试脚本

[root@test-agent zabbix_agentd.d]# sh tcp_status_monitoring_port.sh LISTEN 80
6

4.重启agent

[root@test-agent zabbix_agentd.d]# systemctl restart zabbix-agent

5.server端测试

[root@test-server zabbix]# zabbix_get -s 192.168.1.127 -k tcp.status.count[LISTEN,80]
2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值