一.zabbix监控nginx
1.安装nginx 服务
rpm -ivh nginx-1.8.0-1.el6.ngx.x86_64.rpm
2.编辑nginx的配置文件cd /etc/nginx/conf.d/
vim default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /status {
stub_status on;
# Nginx中的stub_status模块主要用于查看Nginx的一些状态信息. 本模块默认是不会编译进Nginx的,如果你要使用该模块,则要在编译安装Nginx时指定:./configure –with-http_stub_status_module
access_log off;
# 关闭日志记录
allow 127.0.0.1; # 只允许本机访问
deny all;
}
3.利用curl http://127.0.0.1/status访问nginx用来做测试
4.过滤监控参数(访问次数,连接次数等等)
curl -s http://127.0.0.1/status | grep Active | awk ‘{print $NF}’
将过滤出来的参数以key—value键值对的形式存储:
cd /etc/zabbix/zabbix_agentd.d
cp userparameter_mysql.conf userparameter_nginx.conf # 利用监控mysql服务的配置文件模版复制一份给nginx服务
vim userparameter_nginx.conf
UserParameter=nginx.active,curl -s http://127.0.0.1/status | grep Active | awk '{print $NF}' # 获取连接数
UserParameter=nginx.accepts,curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $1}' # 获取接受请求数
UserParameter=nginx.handled,curl -s http://127.0.0.1/status | awk NR==3 | awk '{print $2}'