zabbix自定义监控

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

添加监控项

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

触发器

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值