zabbix自定义监控
文章目录
自定义监控进程
基于昨天的邮箱告警,部署完成后,我们可以编译脚本用来监控进程
首先我们可以在被监控端,开启httpd服务,以便监控
配置监控脚本
//在被监控端,首先修改配置文件
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=check_process[*],/bin/bash /scripts/check_process.sh $1
//重启服务,生效配置
[root@localhost ~]# pkill zabbix
[root@localhost ~]# zabbix_agentd
[root@localhost ~]# ss -anlt |grep 10050
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
//再编写脚本
[root@localhost ~]# mkdir /scripts
[root@localhost ~]# vim /scripts/check_process.sh
#!/bin/bash
#!/bin/bash
count=`ps -ef| grep $1 |grep -Ev "grep|$0" |wc -l`
if [ $count == 0 ];then
echo "1"
else
echo "0"
fi
[root@localhost ~]# chmod +x /scripts/check_process.sh
//检查脚本是否有用
[root@zabbix ~]# zabbix_get -s 192.168.202.139 -k check_process[httpd]
0
[root@zabbix ~]# zabbix_get -s 192.168.202.139 -k check_process[mysql]
1
添加监控项
查看监控数据
添加触发器
手动关闭httpd服务,触发报警
[root@localhost ~]# systemctl stop httpd.service
[root@localhost ~]#
报错
自定义监控日志
编写脚本
这里我们初学者,选择直接白嫖道长成果
道长log脚本日志
//由于是python脚本,还需按照python环境
[root@localhost ~]# dnf -y install python36
[root@localhost ~]# chmod +x /scripts/log.py
我们还是用httpd的错误日志来监控
/首先我们修改agentd配置文件
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
UserParameter=check_logs[*],/scripts/log.py $1 $2 $3
//重启服务生效配置
[root@localhost ~]# pkill zabbix_agentd
[root@localhost ~]# zabbix_agentd
然后是/var/log/httpd目录没有执行权限,我们需要给他添加权限
[root@localhost ~]# ll -d /var/log/httpd/
drwx------ 2 root root 41 Sep 6 13:17 /var/log/httpd/
[root@localhost ~]# chmod 755 /var/log/httpd/
[root@localhost ~]# ll /var/log/httpd/
total 8
-rw-r--r-- 1 root root 0 Sep 6 13:17 access_log
-rw-r--r-- 1 root root 5959 Sep 6 14:16 error_log
//给httpd的error日志,添加一个错误信息
[root@localhost ~]# echo "Error123456" >> /var/log/httpd/error_log
//去服务端检测key是否可用
[root@centos8 ~]# zabbix_get -s 192.168.137.133 -k check_logs[/var/log/httpd/error_log]
1
添加监控项
查看监控数据
添加触发器
手动添加错误日志,触发报警
[root@localhost ~]# echo "Error" >> /var/log/httpd/error_log
[root@localhost ~]#
查看邮箱信息