1. 程式人生 > 其它 >zabbix自定義監控apache

zabbix自定義監控apache

自定義監控apache服務需求

需求:監控apache伺服器狀態,當服務異常時自動上報告警資訊:

思路:在這裡我們已監控apache提供服務監聽的80埠為例:判斷80埠存活,存活為正常,不存活為異常狀態!

修改zabbix-agent配置

# 登陸到需要監控的伺服器上
# 修改配置
[root@web ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
297 ### Option: Include
298 #       You may include individual files or all files in a directory in the configuration file.
299 # Installing Zabbix will create include directory in /usr/local/etc, unless modified during the compile time. 300 # 301 # Mandatory: no 302 # Default: 303 # Include= 304 305 # Include=/usr/local/etc/zabbix_agentd.userparams.conf 306 # Include=/usr/local/etc/zabbix_agentd.conf.d/ # 去掉註釋,引入zabbix_agentd.conf.d/目錄下所有配置檔案
307 Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf :wq

建立自定義監控項

自定義監控項格式:UserParameter=<key>,<shell command> 
注意:
1、key必須全域性唯一
2、命令最好使用全路徑

[root@web ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_apache.conf
UserParameter=apache.status,netstat -lnt|awk -F" " '{print $4}
'|egrep .*:80$ | wc -l :wq [root@web ~]# chown zabbix: /usr/local/zabbix/etc/zabbix_agentd.conf.d/userparameter_apache.conf # 重啟 [root@web ~]# systemctl restart zabbix-agent [root@web ~]# ps -ef|grep zabbix_agent zabbix 77873 1 0 11:27 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf zabbix 77874 77873 0 11:27 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: collector [idle 1 sec] zabbix 77875 77873 0 11:27 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: listener #1 [waiting for connection] zabbix 77876 77873 0 11:27 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: listener #2 [waiting for connection] zabbix 77877 77873 0 11:27 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: listener #3 [waiting for connection] zabbix 77878 77873 0 11:27 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_agentd: active checks #1 [idle 1 sec] root 77990 70712 0 11:28 pts/1 00:00:00 grep --color=auto zabbix_agent # 打印出所有zabbix的key值 [root@web ~]# zabbix_agentd -p ... net.tcp.service[ssh,127.0.0.1,22] [u|0] net.tcp.service.perf[ssh,127.0.0.1,22] [d|0] net.udp.service[ntp,127.0.0.1,123] [u|1] net.udp.service.perf[ntp,127.0.0.1,123] [d|0.0001] system.hostname [s|web] apache.status [t|1]

新建zabbix監控模板

 新建監控項

確定服務正產後,點選新增即可!

 新建觸發器

 找到目標主機-新增模板

 測試

確認新增成功後,我們可以進行測試一下,在被監控主機嘗試開啟和關閉apache伺服器

 結果如下:在儀表盤可以自動告警即可!

 

 可根據服務狀態自動清除告警