zabbix自定义监控

zabbix自定义监控

1.配置监控脚本

//修改配置文件
[root@zwl ~]# vim /usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=check_process[*],/bin/bash /scripts/check_process.sh $1
//重启服务
[root@zwl ~]# pkill zabbix
[root@zwl ~]# zabbix_agentd
[root@zwl ~]# 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                                        0.0.0.0:10051                                    0.0.0.0:*
LISTEN                0                     128                                      127.0.0.1:9000                                     0.0.0.0:*
LISTEN                0                     128                                              *:80                                             *:*
LISTEN                0                     128                                           [::]:22                                          [::]:*
LISTEN                0                     80                                               *:3306                                           *:*
[root@zwl ~]#
//编写脚本
[root@zwl ~]# vim /scripts/check_process.sh
[root@zwl ~]# cat /scripts/check_process.sh
#!/bin/bash

count=`ps -ef| grep $1 |grep -Ev "grep|$0" |wc -l`
if [ $count == 0 ];then
        echo "1"
else
        echo "0"
fi
[root@zwl ~]# chmod +x /scripts/check_process.sh
[root@zwl ~]# ss -antl
State    Recv-Q   Send-Q      Local Address:Port        Peer Address:Port   Process
LISTEN   0        128               0.0.0.0:10050            0.0.0.0:*
LISTEN   0        128               0.0.0.0:22               0.0.0.0:*
LISTEN   0        128                     *:80                     *:*
LISTEN   0        128                  [::]:22                  [::]:*
[root@zwl ~]#
//去服务端检查key是否可用
[root@167 ~]# zabbix_get -s 192.168.159.168 -k check_process[httpd]
0
[root@167 ~]# zabbix_get -s 192.168.159.168 -k check_process[mysql]
1
[root@167 ~]#

添加监控项

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

查看监控的数据

在这里插入图片描述

添加触发器

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

手动关闭httpd服务,触发报警

[root@zwl ~]# ss -antl
State    Recv-Q   Send-Q      Local Address:Port        Peer Address:Port   Process
LISTEN   0        128               0.0.0.0:10050            0.0.0.0:*
LISTEN   0        128               0.0.0.0:22               0.0.0.0:*
LISTEN   0        128                     *:80                     *:*
LISTEN   0        128                  [::]:22                  [::]:*
[root@zwl ~]# systemctl stop httpd.service
[root@zwl ~]# ss -antl
State    Recv-Q   Send-Q      Local Address:Port        Peer Address:Port   Process
LISTEN   0        128               0.0.0.0:10050            0.0.0.0:*
LISTEN   0        128               0.0.0.0:22               0.0.0.0:*
LISTEN   0        128                  [::]:22                  [::]:*
[root@zwl ~]#

在这里插入图片描述

自定义监控日志

编写脚本

//安装python环境
[root@zwl ~]# dnf -y install python36
[root@zwl scripts]# chmod +x log.py
[root@zwl scripts]# ll
total 180
-rwxr-xr-x 1 root root    132 Sep  6 20:14 check_process.sh
-rwxr-xr-x 1 root root 177585 Sep  6 20:44 log.py
[root@zwl scripts]#
//修改agentd配置文件
[root@zwl ~]# vim /usr/local/etc/zabbix_agentd.conf
UserParameter=check_logs[*],/scripts/log.py $1 $2 $3
//重启服务
[root@zwl ~]# pkill zabbix_agentd
[root@zwl ~]# zabbix_agentd
[root@zwl ~]# ss -antl
State    Recv-Q   Send-Q      Local Address:Port        Peer Address:Port   Process
LISTEN   0        128               0.0.0.0:10050            0.0.0.0:*
LISTEN   0        128               0.0.0.0:22               0.0.0.0:*
LISTEN   0        128                  [::]:22                  [::]:*
[root@zwl ~]#
//给/var/log/httpd目录权限
[root@zwl ~]# ll -d /var/log/httpd/
drwx------ 2 root root 41 Sep  6 20:18 /var/log/httpd/
[root@zwl ~]# chmod 755 /var/log/httpd/
[root@zwl ~]# ll -d /var/log/httpd/
drwxr-xr-x 2 root root 41 Sep  6 20:18 /var/log/httpd/
//给httpd的error日志,添加一个错误信息
[root@zwl ~]# echo "Error" >> /var/log/httpd/error_log
//测试一下该脚本是否可用
[root@zwl ~]# /scripts/log.py /var/log/httpd/error_log
1
[root@zwl ~]# /scripts/log.py /var/log/httpd/error_log
0
[root@zwl ~]# cat /tmp/logseek
1013
[root@zwl ~]# echo "Error" >> /var/log/httpd/error_log
[root@zwl ~]# echo "Error" >> /var/log/httpd/error_log
[root@zwl ~]# echo "Error" >> /var/log/httpd/error_log
[root@zwl ~]# cat /tmp/logseek
1031
//去服务端检测key是否可用
[root@167 etc]# zabbix_get -s 192.168.159.168 -k check_logs[/var/log/httpd/error_log1
1
[root@167 etc]# zabbix_get -s 192.168.159.168 -k check_logs[/var/log/httpd/error_log]
0

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

查看监控数据

在这里插入图片描述

添加触发器

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

触发报警

[root@zwl ~]# echo "Error" >> /var/log/httpd/error_log

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值