zabbix自定义监控进程
zabbix自定义监控进程
基于昨天的邮箱告警,部署完成后,我们可以编译脚本用来监控进程
首先我们可以在被监控端,开启httpd服务,以便监控
配置控制脚本
给客户端dnf安装httpd服务,并启动服务
[root@localhost ~]# dnf -y install httpd
[root@localhost ~]# systemctl start httpd
创建脚本存放目录,并编辑脚本
[root@localhost ~]# mkdir /etc/scripts
[root@localhost ~]# cd /etc/scripts/
[root@localhost scripts]# vim check_process.sh
#!/bin/bash
count=$(ps -ef |grep -Ev "grep|$0"|grep $1|wc -l)
if [ $count -eq 0 ];then
echo 0
else
echo 1
fi
[root@localhost scripts]# chmod +x check_process.sh
配置zabbix_agentd文件
[root@localhost ~]# cd /usr/local/etc/
[root@localhost etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d
[root@localhost etc]# vim zabbix_agentd.conf
...
UnsafeUserParameters=1
UserParameter=check_process[*],/bin/bash /etc/scripts/check_process.sh $1
更改配置文件后重启zabbix服务
[root@localhost etc]# pkill zabbix
[root@localhost etc]# zabbix_agentd
(服务端)检测一下check_process能否使用
[root@zabbix ~]# zabbix_get -s 192.168.10.150 -k check_process[httpd]
0
客户端httpd服务正常运行中,所以显示为0
[root@zabbix ~]# zabbix_get -s 192.168.10.150 -k check_process[mysql]
1
客户端没有安装mysql服务,所以显示为1
添加监控项
进入触发页面,添加触发器
手动触发
自定义监控日志
服务端和客户端操作
编写脚本
这里用到python脚本,所有需要安装python环境
[root@localhost ~]# cd /etc/scripts/
[root@localhost scripts]# ls
check_process.sh
[root@localhost scripts]# ls
check_process.sh log.py
[root@localhost scripts]# chmod +x log.py
[root@localhost scripts]# cd
[root@localhost ~]# dnf -y install python36
Complete!
[root@localhost ~]#
修改httpd日志目录权限
[root@localhost ~]# chmod 755 /var/log/httpd/
修改配置文件,重启服务
[root@localhost ~]# cd /usr/local/etc/
[root@localhost etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d
[root@localhost etc]# vim zabbix_agentd.conf
[root@localhost etc]#
...
UserParameter=check_logs[*],/etc/scripts/log.py $1 $2 $3
#直接在最后一行加入此内容
重启服务
[root@localhost etc]# pkill zabbix
[root@localhost etc]# zabbix_agentd
[root@localhost etc]#
服务端测试
[root@localhost ~]# zabbix_get -s 192.168.10.150 -k check_logs['/var/log/httpd/error_log']
0
手动触发警告,查看警告
[root@localhost ~]# cd /var/log/httpd/
[root@localhost httpd]# ls
access_log error_log
[root@localhost httpd]# echo 'Error' >> error_log
[root@localhost httpd]#
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤