自定义监控进程
监控进程步骤:
- 编写脚本,脚本放到统一的位置
- 修改/usr/local/etc/zabbix_agentd.conf文件
- UnsafeUserParameters=1
- UserParameter= < key > , < shell command >
- 重启zabbix_agent
- 在web界面配置监控项和触发器
编写脚本
编写脚本前我们要确定一个防止脚本的位置,因为管理的客户端不止一台主机,如果每台主机上面的脚本放置脚本的位置不一样,在管理起来的时候只会更复杂。
我这里在根目录下创建一个目录scripts,在脚本放在这里
[root@localhost ~]# mkdir /scripts
我们以监控httpd服务进程为例来编写脚本,过滤进程
//开启服务
[root@localhost ~]# systemctl start httpd
//过滤进程
[root@localhost ~]# ps -ef | grep -v grep | grep httpd | wc -l
5
[root@localhost ~]# ps -ef | grep -v grep | grep -c httpd
5
//以上两种过滤方式均可,选择一种使用
编写脚本
[root@localhost ~]# cd /scripts/
[root@localhost scripts]# touch check_httpd.sh
[root@localhost scripts]# chmod +x check_httpd.sh
[root@localhost scripts]# vim check_httpd.sh
#!/bin/bash
count=$(ps -ef | grep -Ev "grep|$0" | grep -c httpd)
if [ $count -eq 0 ];then
echo '1'
else
echo '0'
fi
//测试一下脚本
[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