標籤:nginx
zabbix監控nginx狀態
首先,在nginx的設定檔中添加如下一段代碼
server { listen localhost:80; server_name localhost;location /nginxstatus { stub_status on; access_log off; allow 127.0.0.1;allow 192.168.1.165; deny all; } }
儲存之後重啟nginx
在zabbix指令碼目錄下建立指令碼監控zabbix狀態
#!/bin/bash # Script to fetch nginx statuses for tribily monitoring systems # Set Variables # Functions to return nginx stats nginx=/data/zabbix/sbin/nginx.txtfunction active { curl "http://localhost/nginxstatus"&>$nginx && awk ‘/Active/{print $3}‘ $nginx}function reading { curl "http://localhost/nginxstatus"&>$nginx && awk ‘/Reading/{print $2}‘ $nginx}function writing { curl "http://localhost/nginxstatus"&>$nginx && awk ‘/Writing/{print $4}‘ $nginx}function waiting { curl "http://localhost/nginxstatus"&>$nginx && awk ‘/Waiting/{print $6}‘ $nginx}function accepts { curl "http://localhost/nginxstatus"&>$nginx && awk NR==6 $nginx| awk ‘{print $1}‘}function handled { curl "http://localhost/nginxstatus"&>$nginx && awk NR==6 $nginx| awk ‘{print $2}‘}function requests { curl "http://localhost/nginxstatus"&>$nginx && awk NR==6 $nginx| awk ‘{print $3}‘}# Run the requested function case "$1" inactive) active ;;reading) reading ;;writing) writing ;;waiting) waiting ;;accepts) accepts ;;handled) handled ;;requests) requests ;;*) echo "Usage: $0 {nginx_site_dicovery}" echo "Usage: $0 {active [host] | reading [host] | writing [host] | waiting [host] | accepts [host] | handled [host] | requests [host]}"esac
然後修改該檔案的屬主和屬組為zabbix,並且具有執行許可權
chown zabbix.zabbix /data/zabbix/sbin/nginx_status.sh
chmod 755 /data/zabbix/sbin/nginx_status.sh
再建立一個nginx.txt的檔案,將屬組和屬主定為zabbix,具有讀寫權限
然後在zabbix_agentd.conf設定檔中添加如下代碼
UserParameter=nginx.accepts,/data/zabbix/sbin/nginx_status accepts UserParameter=nginx.handled,/data/zabbix/sbin/nginx_status handled UserParameter=nginx.requests,/data/zabbix/sbin/nginx_status requests UserParameter=nginx.connections.active,/data/zabbix/sbin/nginx_status active UserParameter=nginx.connections.reading,/data/zabbix/sbin/nginx_status reading UserParameter=nginx.connections.writing,/data/zabbix/sbin/nginx_status writing UserParameter=nginx.connections.waiting,/data/zabbix/sbin/nginx_status waiting
建立好了之後就可以在web頁面配置item監控項了.
zabbix監控mysql資料庫狀態
Zabbix自己提供的模板可以監控mysql slow queries,mysqlversion,uptime,alive等。
1.Zabbix官方提供的監控mysql的模板Template AppMySQL,可以看到相關的Items和key。
2.把該模板Template App MySQL Link到相關的主機上面,發現Item的Status是停用,因為key的值是通過Mysql使用者查看"showglobal status"資訊或者用mysqladmin命令查看status或extended-status的資訊而取的值。
mysql> show global status; mysql> show status;
本文出自 “從心開始” 部落格,請務必保留此出處http://hao360.blog.51cto.com/5820068/1639927
zabbix監控nginx,Mysqld,Php狀態