一、自定义监控进程
写脚本,脚本放在统一位置
修改被监控机zabbix_agentd.conf配置文件
UnxsafeParameters=1
UnserParameter=<key>,<command>
重启zabbix_agent
在web界面配置监控项和触发器
监控httpd
// 在客户端安装httpd
[root@centos ~]# yum -y install httpd
[root@centos ~]# systemctl start httpd
[root@centos ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
// 监控httpd进程
[root@centos ~]# ps -ef | grep httpd
root 36614 1 0 22:29 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 37392 36614 0 22:29 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 37393 36614 0 22:29 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 37395 36614 0 22:29 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 37396 36614 0 22:29 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 38613 1473 0 22:30 pts/0 00:00:00 grep --color=auto httpd
修改客户端zabbix_agentd文件zabbix_agentd.conf
[root@centos ~]# cd /usr/local/etc/
[root@centos etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d
[root@centos etc]# vim zabbix_agentd.conf
# Default:
UnsafeUserParameters=1
UserParameter=check_process[*],/scripts/check_process.sh $1
// 修改完配置文件重启服务
[root@centos ~]# pkill zabbix
[root@centos ~]# zabbix_agentd
编写进程然后进行测试
// 创建并进入脚本目录
[root@centos ~]# mkdir /scripts
[root@centos ~]# cd /scripts/
// 编写一个脚本
[root@centos scripts]# vim check_process.sh
#!/bin/bash
web=$( ps -ef | grep -Ev "grep|$0" | grep -c "$1" )
if [ $web -eq 0 ];then
echo '1'
else
echo '0'
fi
[root@centos scripts]# chmod +x check_process.sh
返回服务端查看配置文件是否存在问题
[root@localhost ~]# zabbix_get -s 192.168.91.135 -k check_process[httpd]
0
[root@centos ~]# systemctl stop httpd.service
[root@localhost ~]# zabbix_get -s 192.168.91.135 -k check_process[httpd]
1
在zabbix网页上添加监控项
添加触发器
选择报警程度,填写名字,add添加
二、自定义监控日志
写脚本,脚本放在统一位置
修改被监控机zabbix_agentd.conf配置文件
UnxsafeParameters=1
UnserParameter=<key>,<command>
重启zab