zabbix自定义监控

zabbix自定义监控

1. 进程

//创建一个脚本目录
[root@localhost etc]# mkdir /scripts
[root@localhost etc]# cd /scripts
[root@localhost scripts]# vim check_httpd.sh

//安装httpd 启动 
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# systemctl start httpd

//查看进程号
[root@localhost ~]# ps -ef | grep httpd 
root        5757    1669  0 16:13 pts/2    00:00:00 vim check_httpd.sh
root       21671       1  1 16:16 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     21672   21671  0 16:16 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     21673   21671  1 16:16 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     21681   21671  2 16:16 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     21712   21671  1 16:16 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
root       22056    8831  0 16:16 pts/4    00:00:00 grep --color=auto httpd
[root@localhost ~]# ps -ef | grep -Ev "grep|$0" | grep -c httpd  
6

//写进脚本
#! /bin/bash 
  
count=$(ps -ef | grep -Ev "grep|$0" |grep -c '$1')
if [ $count -eq 0 ];then
    echo '1'
else
    echo '0'
fi 
[root@localhost scripts]# chmod +x check_httpd.sh
[root@localhost scripts]# ./check_httpd.sh 
0

//在配置文件编写
[root@localhost etc]# vim zabbix_agentd.conf
UnsafeUserParameters=1 
UserParameter=check_process[*],/scripts/check_process.sh $1
[root@localhost etc]# pkill zabbix 
[root@localhost etc]# zabbix_agentd 

在这里插入图片描述
[root@server etc]# zabbix_get -s 192.168.200.146 -k check_process
0

添加触发器
在这里插入图片描述
测试结果
在这里插入图片描述

2. 日志文件

作用:检查日志文件中是否有指定的关键字
第一个参数为日志文件名(必须有,相对路径、绝对路径均可)
第二个参数为seek position文件的路径(可选项,若不设置则默认为/tmp/logseek文件。相对路径、绝对路径均可)
第三个参数为搜索关键字,默认为 Error

//安装python
[root@localhost scripts]# yum -y install python3

//测试 
[root@localhost scripts]# ./log.py /var/log/httpd/error_log 
0
[root@localhost scripts]# echo "Error" >> /var/log/httpd/error_log
[root@localhost scripts]# ./log.py /var/log/httpd/error_log 
1

//修改配置文件
[root@localhost etc]# vim zabbix_agentd.conf
UserParameter=check_log[*],/scripts/check_log.py $1 $2 $3
[root@localhost etc]# pkill zabbix
[root@localhost etc]# zabbix_agentd

添加监控项
在这里插入图片描述

添加触发器
在这里插入图片描述
在这里插入图片描述
[root@localhost scripts]# echo “Error” >> /var/log/httpd/error_log

在这里插入图片描述
多个值
在这里插入图片描述
[root@localhost scripts]# echo “error” >> /var/log/httpd/error_log
在这里插入图片描述

3. mysql主从

//在家目录下编写一个配置文件 里面存放用户和密码
[root@localhost ~]# pwd
/root
[root@localhost ~]# vim .my.cnf
[root@localhost ~]# cat .my.cnf 
[client]
user=root
password=123456

//编写脚本
[root@localhost scripts]# cat check_mysql.sh
#! /bin/bash
user=zabbix
pass=123456

count=$( mysql -u$user -p$pass -e 'show slave status\G'|grep '_Running:'|grep -c 'Yes')
if [ $count -ne 2 ];then
    echo '1'
else 
    echo '0'
fi
[root@localhost scripts]# ./check_mysql.sh 
0                               //0代表没问题

//修改aengtd配置文件
[root@localhost scripts]# vim /usr/local/etc/zabbix_agentd.conf
UserParameter=check_mysql.replication,/scripts/check_mysql.sh
[root@localhost scripts]# pkill zabbix 
[root@localhost scripts]# zabbix_agentd

//授权zabbix用户
MariaDB [(none)]> grant SUPER,REPLICATION CLIENT on *.* to 'zabbix'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec)

//在server上测试
[root@server ~]# zabbix_get  -s 192.168.200.146 -k check_mysql.replication
0

创建监控项
在这里插入图片描述
创建触发器
在这里插入图片描述

//停掉slave
MariaDB [(none)]> stop slave;
Query OK, 0 rows affected (0.001 sec)

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

4. mysql主从延迟

//编写脚本
[root@localhost scripts]# cat ./check_mysql_delay.sh
#! /bin/bash 

delay_count=$(mysql -uzabbix -p123456 -e 'show slave status\G'|grep 'Behind' |awk '{print $2}')
if [ $delay_count -ne 0 ];then
    echo $delay_conut
else 
    echo '0'
fi

//编写配置文件
[root@localhost scripts]# vim /usr/local/etc/zabbix_agentd.conf
UserParameter=check_replication_delay,/scripts/check_mysql_delay.sh
[root@localhost scripts]# pkill zabbix 
[root@localhost scripts]# zabbix_agentd 

//测试
[root@server ~]# zabbix_get  -s 192.168.200.146 -k check_replication_delay
0

添加监控项
在这里插入图片描述
添加触发器
在这里插入图片描述
因为实验环境延迟达不到200以上 所以报不了错
在这里插入图片描述

5.用户和组权限设置

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

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

6.声音报警

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值