zabbix自定义监控配置
[root@web01 ~]# mkdir /scripts
//编写
[root@web01 ~]# vim /scripts/check_process.sh
#!/bin/bash
status=$(ps -ef |grep $1|grep -Ev "$0|grep"|wc -l)
if [ $status -eq 0 ];then
echo '1'
else
echo '0'
fi
//让该脚本有执行的权限
[root@web01 scripts]# chmod +x check_process.sh
[root@web01 scripts]# ll
total 4
-rwxr-xr-x 1 root root 124 Sep 6 11:35 check_process.sh
[root@web01 ~]# vim /usr/local/zabbix_agent/etc/zabbix_agentd.conf
UnsafeUserParameters=1 #是否启用自定义监控项,可选值为{1|0}
UserParameter=check_process[*],/bin/bash /scripts/check_process.sh $1
//重启agent,生效作更改的配置
[root@web01 ~]# pkill zabbix_agent
[root@web01 ~]# /usr/local/zabbix_agent/sbin/zabbix_agentd
//在Server端测试刚刚所做的进程监控配置
//在agent端yum安装一个httpd服务,但没有mysql服务。测试结果如下
[root@zabbix ~]# zabbix_get -s 192.168.92.130 -k check_process[httpd]
0
[root@zabbix ~]# zabbix_get -s 192.168.92.130 -k check_process[mysql]
1
添加监控项
添加触发器
触发警告
[root@localhost etc]# systemctl stop httpd
[root@localhost etc]# 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 [::]:22 [::]:*
![在这里插入图片描述](https://img-blog.csdnimg.cn/97b5e761e37940d08fd3a193dee469e4.png#pic_center)
## 自定义监控日志
脚本
```powershell
[root@localhost scripts]# ls
check_process.sh log.py
[root@localhost scripts]# chmod +x log.py
//安装python环境
[root@localhost ~]# dnf -y install python36
//用httpd错误日志监控
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=check_process[*],/bin/bash /scripts/check_process.sh $1
UserParameter=check_logs[*],/scripts/log.py $1 $2 $3 //新添加此行配置
//重启生效
[root@localhost ~]# pkill zabbix_agentd
[root@localhost ~]# zabbix_agentd
//添加权限
[root@localhost ~]# ll -d /var/log/httpd/
drwx------. 2 root root 41 Sep 6 17:03 /var/log/httpd/
[root@localhost ~]# chmod 755 /var/log/httpd/
[root@localhost ~]# ll /var/log/httpd/
total 4
-rw-r--r--. 1 root root 0 Sep 6 17:03 access_log
-rw-r--r--. 1 root root 2358 Sep 6 18:34 error_log
//添加一个错误信息
[root@localhost ~]# echo "Error!" >> /var/log/httpd/error_log
//在服务端检测key是否可用
[root@localhost ~]# zabbix_get -s 192.168.183.138 -k check_logs[/var/log/httpd/error_log]
1
添加监控项
触发器