首页 > 其他 > 详细

zabbix自定义监控

时间:2021-05-23 17:19:41      阅读:14      评论:0      收藏:0      [点我收藏+]

1.环境说明:

环境 ip hostname 要安装的应用
服务器 192.168.59.131 server lamp架构
zabbix server
zabbix agent
客户端 192.168.59.133 139 zabbix agent
  
 
 
 
 
 
 
 

2.网页配置主机

监控进程

技术分享图片

 

 客户端: 打开自定义监控的功能

[root@139 ~]# cd /usr/local/etc
[root@139 etc]# ls
zabbix_agentd.conf  zabbix_agentd.conf.d
[root@139 etc]# vim zabbix_agentd.conf

UnsafeUserParameters=1

UserParameter=check_process[*],/bin/bash /scripts/check_process.sh $1


 #重启服务

[root@139 etc]# pkill zabbix
[root@139 etc]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@139 etc]# zabbix_agentd
[root@139 etc]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
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 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*

 

创建目录编写脚本

[root@139 etc]# mkdir /scripts
[root@139 etc]# ls /
bin/     dev/     home/    lib64/   mnt/     proc/    run/     scripts/ sys/     usr/     
boot/    etc/     lib/     media/   opt/     root/    sbin/    srv/     tmp/     var/     
[root@139 etc]# cd /scripts/
[root@139 scripts]# vim check_process.sh

#!/bin/bash
  

process_status=$(ps -ef|grep -Ev "grep|$0"|grep -c $1)

if[$process_status -eq 0 ];then
     echo 1
 else
     echo 0
fi


#添加执行权限
[root@139 scripts]# chmod +x check_process.sh

监控端验证


[root@139 etc]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
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 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*



[
root@server ~]# zabbix_get -s 192.168.59.133 -k check_process[‘httpd‘] 0

网页配置监控项

技术分享图片

 

 技术分享图片

验证

 停止http服务后

技术分享图片

 

 技术分享图片

 

 

监控log日志文件

验证脚本

[root@139 script./log.py  /var/log/httpd/error_log_log 
0
[root@139 scripts]# echo Error >> /var/log/httpd/error_log 
[root@139 scripts]# echo qwe >> /var/log/httpd/error_log 
[root@139 scripts]# echo qwe >> /var/log/httpd/error_log 
[root@139 scripts]# echo qwe >> /var/log/httpd/error_log 
[root@139 scripts]# echo qwe >> /var/log/httpd/error_log 
[root@139 scripts]# ./log.py  /var/log/httpd/error_log 
1

添加配置文件

[root@139 scripts]# vim /usr/local/etc/zabbix_agentd.conf

UserParameter=check_log[*],/scripts/log.py $1 $2 $3
#重启服务
[root@139 scripts]# pkill zabbix
[root@139 scripts]# zabbix_agentd 
#添加权限

[root@139 ~]# setfacl -m u:zabbix:rx /var/log/httpd/

到服务器监控

[root@server ~]# zabbix_get -s 192.168.59.133 -k check_log[‘/var/log/httpd/error_log‘]
1

网页端配置

技术分享图片

 

 技术分享图片

 

 验证

[root@139 scripts]# echo Error >> /var/log/httpd/error_log 

技术分享图片

 

 

 

 

 

 

 

 

zabbix自定义监控

原文:https://www.cnblogs.com/Mariko/p/14801411.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!