标签: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.txt function 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" in active) 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
标签:nginx
原文地址:http://hao360.blog.51cto.com/5820068/1639927