zabbix自定义监控--进程

编写脚本

[root@localhostetc]# mkdir  /scripts
[root@localhost scripts]# touch check_httpd.sh
[root@localhost scripts]# chmod +x check_httpd.sh 
[root@localhost scripts]# vim check_process.sh
#!/bin/bash
  
count=$(ps -ef | grep -Ev "grep|$0" | grep -c "$1")
if [ $count -eq 0 ];then
    echo '1'
else
    echo '0'
fi

修改配置文件

[root@localhost ~]# cd /usr/local/etc/
[root@localhost etc]# vim zabbix_agentd.conf
...
UnsafeUserParameters=1
...
# 配置文件末尾添加
UserParameter=check_process[*],/scripts/check_process.sh  $1
//“check_process[*]”是在web界面中要写的key *表示某个服务,$1的参数来自于check_process[*]
也就是说check_process[*]中*是什么服务,$1就会传什么服务名
例如httpd:
web界面中的key是 check_process[httpd] 说明是监控httpd服务是否开启

重启

[root@localhost ~]# pkill zabbix
[root@localhost ~]# zabbix_agentd 

测试

[root@localhost scripts]# ./check_httpd.sh 
1
[root@localhost scripts]# ss -antl 
State      Recv-Q      Send-Q           Local Address:Port            Peer Address:Port     Process     
LISTEN     0           128                    0.0.0.0:10050                0.0.0.0:*                    
LISTEN     0           128                    0.0.0.0:22                   0.0.0.0:*                    
LISTEN     0           128                          *:80                         *:*                    
LISTEN     0           128                       [::]:22                      [::]:*                    
[root@localhost scripts]# ./check_httpd.sh 
0
//服务是开启状态,所有测试脚本的时候是0,如果关闭服务,运行脚本结果则为1

web界面监控
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
关闭客户端httpd服务

[root@localhost scripts]# ss -antl
State   Recv-Q  Send-Q    Local Address:Port      Peer Address:Port  
LISTEN  0       128             0.0.0.0:10050          0.0.0.0:*     
LISTEN  0       128             0.0.0.0:22             0.0.0.0:*     
LISTEN  0       128                   *:80                   *:*     
LISTEN  0       128                [::]:22                [::]:*     
[root@localhost scripts]# systemctl stop  httpd.service 

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值