博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
利用Zabbix监控Nginx
阅读量:4106 次
发布时间:2019-05-25

本文共 2460 字,大约阅读时间需要 8 分钟。

利用Zabbix监控Nginx

转自

http://www.linuxidc.com/Linux/2012-07/64798.htm

近段时间一直在使用zabbix,让其监控更多的东西,目前我也在一步一步实现原计划。不得不说它的自由定制功能真是很强!开工吧。

实现监控需要三个步骤:

1、自己创建或是导入模版。<附件>

2、nginx需要配置status。

这个因环境而已,我贴上我的吧。 

server {   
listen 80;  
server_name xxx.xxx.xxx.xxx;  
index index.html login.jsp;  
root /www/freetrade;  
access_log off;  
error_log off;  
location /nginx {  
stub_status on;  
access_log off;  
allow 127.0.0.1;  
allow xxx.xxx.xxx.xxx;  
deny all;  
}  
}

3、改客户端配置文件,使用脚本。

在客户端机器上任意位置放这个脚本,不过我还是建议你规范的放在一个地方。我在作者的基础上改了一下,适合自己的需求。

#!/bin/bash   
# Script to fetch nginx statuses for tribily monitoring systems  
# Author: krish@toonheart.com  
# License: GPLv2 
 
# Set Variables  
HOST=`/sbin/ifconfig eth0 | sed -n '/inet /{s/.*addr://;s/ .*//;p}'`  
PORT="80" 
 
# Functions to return nginx stats 
 
function active {  
/usr/bin/curl "http://$HOST:$PORT/nginx" 2 > /dev/null| grep 'Active' | awk '{print $NF}'  
 
function reading {  
/usr/bin/curl "http://$HOST:$PORT/nginx" 2 > /dev/null| grep 'Reading' | awk '{print $2}'  
 
function writing {  
/usr/bin/curl "http://$HOST:$PORT/nginx" 2>/dev/null| grep 'Writing' | awk '{print $4}'  
 
function waiting {  
/usr/bin/curl "http://$HOST:$PORT/nginx" 2 > /dev/null| grep 'Waiting' | awk '{print $6}'  
 
function accepts {  
/usr/bin/curl "http://$HOST:$PORT/nginx" 2 > /dev/null| awk NR==3 | awk '{print $1}'  
 
function handled {  
/usr/bin/curl "http://$HOST:$PORT/nginx" 2 > /dev/null| awk NR==3 | awk '{print $2}'  
 
function requests {  
/usr/bin/curl "http://$HOST:$PORT/nginx" 2 > /dev/null| awk NR==3 | awk '{print $3}'  
 
# Run the requested function  
$1 

修改客户端/etc/zabbix/zabbix_agentd.conf 环境不同,文件位置不同。 

#monitor nginx   
UserParameter=nginx.accepts,/etc/zabbix/scripts/nginx_status accepts  
UserParameter=nginx.handled,/etc/zabbix/scripts/nginx_status handled  
UserParameter=nginx.requests,/etc/zabbix/scripts/nginx_status requests  
UserParameter=nginx.connections.active,/etc/zabbix/scripts/nginx_status active  
UserParameter=nginx.connections.reading,/etc/zabbix/scripts/nginx_status reading  
UserParameter=nginx.connections.writing,/etc/zabbix/scripts/nginx_status writing  
UserParameter=nginx.connections.waiting,/etc/zabbix/scripts/nginx_status waiting 

有图才有真相!<几台空闲的nginx>

相关附件下载

免费下载地址在 

用户名与密码都是

具体下载目录在 /2012年资料/7月/9日/利用Zabbix监控Nginx/

转载地址:http://ispsi.baihongyu.com/

你可能感兴趣的文章
PHP 7 的五大新特性
查看>>
PHP底层的运行机制与原理
查看>>
深入了解php底层机制
查看>>
PHP中的stdClass 【转】
查看>>
XHProf-php轻量级的性能分析工具
查看>>
PHP7新特性 What will be in PHP 7/PHPNG
查看>>
比较strtr, str_replace和preg_replace三个函数的效率
查看>>
PHP编译configure时常见错误 debian centos
查看>>
configure: error: Please reinstall the BZip2 distribution
查看>>
OpenCV gpu模块样例注释:video_reader.cpp
查看>>
【增强学习在无人驾驶中的应用】
查看>>
OpenCV meanshift目标跟踪总结
查看>>
那些人生“开挂”的程序员,都在干什么?
查看>>
影响科学圈的那些计算机代码
查看>>
乐视视频 App 图标改为“欠 122 亿”,网友:我在别家分红包,却在你家随份子!...
查看>>
为何程序员总喜欢写技术博客,看完恍然大悟...
查看>>
如何判断一家互联网公司要倒闭了?
查看>>
想快速上手机器学习?来看下这个 GitHub 项目!
查看>>
GitHub 标星 3.6k,一本开源的深度学习中文教程!
查看>>
9 款你不能错过的 JSON 工具
查看>>