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