草庐IT

zabbix3.0.4监控nginx性

wg_iiGidEaB 2023-03-28 原文
zabbix agentd客户端上,查看nginx是否加载了–with-http_stub_status_module。因为zabbix监控nginx是根据nginx的Stub Status模块,抓取Status模块所提供的数据。假如以前没开启,现在想启用StubStatus 模块,在编译nginx 的时候要加上参数 –with-http_stub_status_module,执行./configure && make就可以了,不用make install。不过,一般情况下都是安装了的。


检查with-http_stub_status_module有没有安装


nginx status 开启方法:


server {  ...  location /status {  stub_status on;  access_log off;  allow 123.123.123.123; # zabbix服务器IP地址,一般是内网地址。  allow 127.0.0.1;  deny all;  }在nginx配置文件中:


启动nginx

[root@iZ25sh42s8wZ vhosts]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@iZ25sh42s8wZ vhosts]# /etc/init.d/nginx reload Reloading Nginx: [ OK ]

用curl做测试


状态页面各项数据的意义:
active connections – 当前 Nginx 正处理的活动连接数。
serveraccepts handled requests — 总共处理了 233851 个连接 , 成功创建 233851 次握手 (证明中间没有失败的 ), 总共处理了 687942 个请求 ( 平均每次握手处理了 2.94 个数据请求 )。
reading — nginx 读取到客户端的 Header 信息数。
writing — nginx 返回给客户端的 Header 信息数。
waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading + writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接。



zabbix-agent 配置

有3个步骤,首先是编写获取Nginx信息脚本,接着配置中增加key信息,然后重启agent 服务。

①编写Nginx监控脚本,记住路径,后面配置需要用到,注意脚本权限问题,agent运行用户要能执行。

mkidr -p /usr/local/zabbix-agent/scripts/

cd /usr/local/zabbix-agent/scripts

vi nginx-check.sh

#!/bin/bash

##################################

# Zabbix monitoring script

#

# nginx:

# - anything available via nginx stub-status module

#

##################################

# Contact:

# vincent.viallet@gmail.com

# Zabbix requested parameter

ZBX_REQ_DATA="$1"

ZBX_REQ_DATA_URL="$2"

# Nginx defaults

NGINX_STATUS_DEFAULT_URL="http://bbs.jzq.pub/nginx-status"    #(这里写网站的域名)

WGET_BIN="/usr/bin/wget"

#

# Error handling:

# - need to be displayable in Zabbix (avoid NOT_SUPPORTED)

# - items need to be of type "float" (allow negative + float)

#

ERROR_NO_ACCESS_FILE="-0.9900"

ERROR_NO_ACCESS="-0.9901"

ERROR_WRONG_PARAM="-0.9902"

ERROR_DATA="-0.9903" # either can not connect / bad host / bad port

# Handle host and port if non-default

if [ ! -z "$ZBX_REQ_DATA_URL" ]; then

 URL="$ZBX_REQ_DATA_URL"

else

 URL="$NGINX_STATUS_DEFAULT_URL"

fi

# save the nginx stats in a variable for future parsing

NGINX_STATS=$($WGET_BIN -q $URL -O - 2> /dev/null)

# error during retrieve

if [ $? -ne 0 -o -z "$NGINX_STATS" ]; then

 echo $ERROR_DATA

 exit 1

fi

#

# Extract data from nginx stats

#

case $ZBX_REQ_DATA in

 active_connections) echo "$NGINX_STATS" | head -1 | cut -f3 -d' ';;

 accepted_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f2 -d' ';;

 handled_connections) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f3 -d' ';;

 handled_requests) echo "$NGINX_STATS" | grep -Ev '[a-zA-Z]' | cut -f4 -d' ';;

 reading) echo "$NGINX_STATS" | tail -1 | cut -f2 -d' ';;

 writing) echo "$NGINX_STATS" | tail -1 | cut -f4 -d' ';;

 waiting) echo "$NGINX_STATS" | tail -1 | cut -f6 -d' ';;

 *) echo $ERROR_WRONG_PARAM; exit 1;;

esac

exit 0

~

chmod o+x /usr/local/zabbix-agent/scripts/nginx-check.sh


agent的配置文件 /etc/zabbix/zabbix_agentd.conf 中定义了其他key的包含目录 Include=/etc/zabbix/zabbix_agentd.d/, 如果没有这个配置请自己添加下。接着在 /etc/zabbix/zabbix_agentd.d/ 目录新建一个文件 nginx-params.conf, 内容如下

加入以下内容:

UserParameter=nginx[*],/usr/local/zabbix-agent/scripts/nginx-check.sh "$1"


/etc/init.d/zabbix-agent restart




模板文件比较长留一个下载地址https://github.com/jizhang/zabbix-templates/blob/master/nginx/nginx-template.xml


在新建的主机--选择该模板。


有关zabbix3.0.4监控nginx性的更多相关文章

  1. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

  2. Observability:从零开始创建 Java 微服务并监控它 (二) - 2

    这篇文章是继上一篇文章“Observability:从零开始创建Java微服务并监控它(一)”的续篇。在上一篇文章中,我们讲述了如何创建一个Javaweb应用,并使用Filebeat来收集应用所生成的日志。在今天的文章中,我来详述如何收集应用的指标,使用APM来监控应用并监督web服务的在线情况。源码可以在地址 https://github.com/liu-xiao-guo/java_observability 进行下载。摄入指标指标被视为可以随时更改的时间点值。当前请求的数量可以改变任何毫秒。你可能有1000个请求的峰值,然后一切都回到一个请求。这也意味着这些指标可能不准确,你还想提取最小/

  3. ruby-on-rails - 如何用不同的用户运行nginx主进程 - 2

    A/ctohttp://wiki.nginx.org/CoreModule#usermaster进程曾经以root用户运行,是否可以以不同的用户运行nginxmaster进程? 最佳答案 只需以非root身份运行init脚本(即/etc/init.d/nginxstart),就可以用不同的用户运行nginxmaster进程。如果这真的是你想要做的,你将需要确保日志和pid目录(通常是/var/log/nginx&/var/run/nginx.pid)对该用户是可写的,并且您所有的listen调用都是针对大于1024的端口(因为绑定(

  4. jquery - Ruby 1.9.1、Rails 2.3.2 和 jrails 0.4 出现 "rescue in const_missing"错误 - 2

    我最近开始了一个项目,团队决定我们希望使用jQuery而不是Prototype/Scriptaculous来满足我们的javascript需求。我们设置了我们的项目,并开始切换。插件已安装viatheseinstructions,一切都按计划进行。不久之后,当尝试运行“./script/server”时,我们收到以下错误:=>Rails2.3.2applicationstartingonhttp://0.0.0.0:3000/usr/local/lib/ruby/gems/1.9.1/gems/activesupport-2.3.2/lib/active_support/depende

  5. ruby-on-rails - Websocket-rails 不适用于 Nginx 和 Unicorn 的生产环境 - 2

    我有带有gemwebsocket-rails0.7的Rails3.2应用程序。在开发机上,一切正常在生产环境中,我使用Nginx/1.6作为代理服务器,Unicorn作为http服务器。Thin用于独立模式(在https://github.com/websocket-rails/websocket-rails/wiki/Standalone-Server-Mode之后)。nginx配置:location/websocket{proxy_passhttp://localhost:3001/websocket;proxy_http_version1.1;proxy_set_headerUp

  6. ruby - 没有 nginx 的 Puma - 同一 IP 上的多个 ruby​​ 应用程序 :PORT - 2

    Nginx在生产中的重要性通常基于它为慢速客户端提供服务的能力;在RESTfulAPI的设置中,它似乎是生产堆栈的一个不必要的层,尤其是Puma(不像广泛使用的unicorn可以处理nginx工作)。Pumacanallowmultipleslowclientstoconnectwithoutrequiringaworkertobeblockedontherequesttransaction.Becauseofthis,Pumahandlesslowclientsgracefully.HerokurecommendsPumaforuseinscenarioswhereyouexpect

  7. ruby-on-rails - Foreman无法启动Nginx,但我可以手动启动。为什么? - 2

    我目前正在运行Foreman在暂存(Ubuntu)上,一旦我开始工作,就会切换到使用upstart。我的Procfile.staging看起来像这样:nginx:sudoservicenginxstartunicorn:bundleexecunicorn-c./config/unicorn.rbredis:bundleexecredis-serversidekiq:bundleexecsidekiq-v-C./config/sidekiq.yml我可以使用以下方法成功启动nginx:$sudoservicenginxstart然而,当我运行$foremanstart时,当其他三个进程成

  8. Linux操作系统CentOS7安装Nginx[详细版] - 2

    Nginx安装1.官网下载Nginx2.使用XShell和Xftp将压缩包上传到Linux虚拟机中3.解压文件nginx-1.20.2.tar.gz4.配置nginx5.启动nginx6.拓展(修改端口和常用命令)(一)修改nginx端口(二)常用命令1.官网下载Nginxhttp://nginx.org/en/download.html这里我下载的是1.20.2版本,大家按需下载对应稳定版即可2.使用XShell和Xftp将压缩包上传到Linux虚拟机中没有XShell可以参考《Linux操作系统CentOS7连接XShell》3.解压文件nginx-1.20.2.tar.gz1)检查是否存

  9. ruby-on-rails - 监控多个 Rails 应用程序 - 2

    是否可以在我的服务器上运行任何工具来监控多个Rails应用程序?我需要监控每个应用程序收到的请求数、每个应用程序使用了多少内存、使用了多少CPU以及其他类似的统计信息。我需要查看每个单独的Rails应用程序的统计信息。 最佳答案 我建议你试试NewRelicRPM.免费版:RPMLiteisthemostwidelyusedsolutionforbasicwebapplicationmonitoring.RPMLiteprovidesapplicationmonitoringforunlimitedJava,RubyorJRubya

  10. ruby-on-rails - ubuntu 14.04 上 passenger-install-nginx-module 的 Bundler 错误 - 2

    我正在ubuntu14.04和ruby2.2.4上安装passenger+nginx。passenger-install-nginx-module有bundler错误$passenger-install-nginx-module/home/ubuntu/.rvm/gems/ruby-2.2.4/gems/bundler-1.13.1/lib/bundler/rubygems_ext.rb:45:in`full_gem_path':uninitializedconstantBundler::Plugin::API::Source(NameError)from/home/ubuntu/.r

随机推荐