前期准备:nginx在编译是必须要加如下参数:

并且要在nginx的配置文件中添加如下配置:

server {
listen *: default_server;
server_name localhost;
location /nginx_status
{
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}

1、安装zabbix-agent
yum -y install zabbix-2.4.8-1.el6.x86_64.rpm zabbix-agent-2.4.8-1.el6.x86_64.rpm
2、编辑agent端的/etc/zabbix/zabbix_agentd.conf文件修改如下内容:
Server=127.0.0.1
换成:(红色字体是你自己的Server端的ip)
Server=Zabbix-Server-IP
3、将nginx_status.sh文件放入/etc/zabbix/zabbix_agentd.d/目录下
nginx_status.sh内容如下:

#!/bin/bash
# Author: fansik
# Description: Statistics the number of nginx state connections
# Date: Wed Sep :: CST
nginx_status_fun(){
ServerName="127.0.0.1"
nginx_active(){
/usr/bin/curl "http://"$ServerName"/nginx_status/" > /dev/null | grep "Active" | awk '{print $NF}'
}
nginx_reading(){
/usr/bin/curl "http://"$ServerName"/nginx_status/" > /dev/null | grep "Reading" | awk '{print $2}'
}
nginx_writing(){
/usr/bin/curl "http://"$ServerName"/nginx_status/" > /dev/null | grep "Writing" | awk '{print $4}'
}
nginx_waiting(){
/usr/bin/curl "http://"$ServerName"/nginx_status/" > /dev/null | grep "Waiting" | awk '{print $6}'
}
nginx_accepts(){
/usr/bin/curl "http://"$ServerName"/nginx_status/" > /dev/null | awk 'NR==3{print $1}'
}
nginx_handled(){
/usr/bin/curl "http://"$ServerName"/nginx_status/" > /dev/null | awk 'NR==3{print $2}'
}
nginx_requests(){
/usr/bin/curl "http://"$ServerName"/nginx_status/" > /dev/null | awk 'NR==3{print $3}'
}
case $ in
active)
nginx_active;
;;
reading)
nginx_reading;
;;
writing)
nginx_writing;
;;
waiting)
nginx_waiting;
;;
accepts)
nginx_accepts;
;;
handled)
nginx_handled;
;;
requests)
nginx_requests;
;;
esac
}
nginx_status_fun $

4、将status.conf文件放入/etc/zabbix/zabbix_agentd.d/目录下
status.conf内容如下:

UserParameter=nginx_status[*],/etc/zabbix/zabbix_agentd.d/nginx_status.sh "$1"

5、赋予nginx_status.sh文件的执行权限:
chmod +x /etc/zabbix/zabbix_agentd.d/nginx_status.sh

6、启动zabbix-agentd服务
/etc/init.d/zabbix-agent start

7、添加nginx的监控模板
添加nginx_status监控的模板

8、添加Application

9、添加item(其余六个分别是nginx_status.sh中case的内容)

10、将起个状态放到一个graph中

11、结果展示

最新文章

  1. EntityFramework 分页问题探讨之 OrderBy
  2. 马士兵Java视频教程 —— 学习顺序
  3. sql:sum(value)与count(letter),当用户不存在时查询到的值
  4. 【leetcode】Pow(x,n)
  5. boost -- scoped_lock V.S. mutex lock/unlock —— why scoped_lock is recommanded?
  6. python-可变迭代对象在for循环中的风险Risk in FOR loop while looping mutable iterable object
  7. mysql 密码篇
  8. C#在Winform中改变Textbox高度三种方法
  9. 1.2……初识Android开发
  10. Lombok(1.14.8) - @SneakyThrows
  11. VS2010界面主题更换全过程
  12. webpack打包sass
  13. warning:1071 (42000) Specified key was too long;max key length is 1000 bytes
  14. sqoop 1.4.4-cdh5.1.2快速入门
  15. hive大数据倾斜总结
  16. CSS中设置margin:0 auto; 水平居中无效的原因分析
  17. 【译】gRPC负载均衡
  18. hdfs api
  19. Luogu P3168 [CQOI2015]任务查询系统
  20. remote: GitLab: You are not allowed to push code to protected branches on this project.

热门文章

  1. 基于FPGA实现的高速串行交换模块实现方法研究
  2. C#检测浏览器类型 Detect Browser
  3. MySQL:系列合集
  4. linux系统之free命令详解
  5. 参数化--每个vuser使用不同的参数值
  6. Linux 脚本点滴知识积累
  7. 【翻译自mos文章】在Oracle GoldenGate中循环使用ggserr.log的方法
  8. implode 把数组 组成一个字符串
  9. Datagrid方法扩展 - tooltip
  10. day12闭包,装饰器