


[Zabbix30] Add Nginx monitoring zabbix get zabbix client installation grafana zabbi
通过Nginx的http_stub_status_module模块提供的状态信息来监控,所以在Agent端需要配置Nginx状态获取的脚本,和添加key信息等,然后在Server端配置Nginx的监控模板等。请根据自己情况调整,这里只做简单的参照。
主要是使用Github这个项目的代码 zabbix-templates
Agent端
系统是Centos6.x, Zabbix-agent是3.0版本, Nginx1.9.x 官方版本
首先要检查Nginx是否安装了 http_stub_status_module
模块,通过下面的命令可以看到编译参数。
<code>nginx <span>-V</span></code>
如果没有这个模块,还需要重新编译Nginx.
配置Nginx
Nginx 80端口的server配置增加如下的片段
<code><span>location</span> /nginx_status { <span>stub_status</span><span>on</span>; <span>access_log</span><span>off</span>; <span>allow</span><span>127.0.0.1</span>; <span>deny</span> all; }</code>
配置完成之后,redload nginx,然后用简单测试下
<code>>> curl http:<span>//127.0.0.1/nginx_status</span> Active connections: <span>7</span><span>server</span> accepts handled requests <span>2707</span><span>2707</span><span>12528</span> Reading: <span>0</span> Writing: <span>1</span> Waiting: <span>6</span>?</code>
zabbix-agent 配置
有3个步骤,首先是编写获取Nginx信息脚本,接着配置中增加key信息,然后重启agent 服务。
- 编写Nginx监控脚本,记住路径,后面配置需要用到。
!!注意脚本权限问题,agent运行用户要能执行。
<code>>><span># mkdir -p /usr/local/zabbix-agent/scripts</span> >><span># cd /usr/local/zabbix-agent/scripts</span> >><span># vim nginx-check.sh</span> >><span># cat nginx-check.sh</span><span>#!/bin/bash</span><span>##################################</span><span># Zabbix monitoring script</span><span>#</span><span># nginx:</span><span># - anything available via nginx stub-status module</span><span>#</span><span>##################################</span><span># Contact:</span><span># vincent.viallet@gmail.com</span><span># Zabbix requested parameter</span> ZBX_REQ_DATA=<span>"<span>$1</span>"</span> ZBX_REQ_DATA_URL=<span>"<span>$2</span>"</span><span># Nginx defaults</span> NGINX_STATUS_DEFAULT_URL=<span>"http://127.0.0.1/nginx_status"</span> WGET_BIN=<span>"/usr/bin/wget"</span><span>#</span><span># Error handling:</span><span># - need to be displayable in Zabbix (avoid NOT_SUPPORTED)</span><span># - items need to be of type "float" (allow negative + float)</span><span>#</span> ERROR_NO_ACCESS_FILE=<span>"-0.9900"</span> ERROR_NO_ACCESS=<span>"-0.9901"</span> ERROR_WR>"-0.9902" ERROR_DATA=<span>"-0.9903"</span><span># either can not connect / bad host / bad port</span><span># Handle host and port if non-default</span><span>if</span> [ ! -z <span>"<span>$ZBX_REQ_DATA_URL</span>"</span> ]; <span>then</span> URL=<span>"<span>$ZBX_REQ_DATA_URL</span>"</span><span>else</span> URL=<span>"<span>$NGINX_STATUS_DEFAULT_URL</span>"</span><span>fi</span><span># save the nginx stats in a variable for future parsing</span> NGINX_STATS=$(<span>$WGET_BIN</span> -q <span>$URL</span> -O - <span>2</span>> /dev/null) <span># error during retrieve</span><span>if</span> [ $? <span>-ne</span><span>0</span> -o -z <span>"<span>$NGINX_STATS</span>"</span> ]; <span>then</span><span>echo</span><span>$ERROR_DATA</span><span>exit</span><span>1</span><span>fi</span><span>#</span><span># Extract data from nginx stats</span><span>#</span><span>case</span><span>$ZBX_REQ_DATA</span><span>in</span> active_connections) <span>echo</span><span>"<span>$NGINX_STATS</span>"</span> | head -<span>1</span> | cut <span>-f</span>3 <span>-d</span><span>' '</span>;; accepted_connections) <span>echo</span><span>"<span>$NGINX_STATS</span>"</span> | grep -Ev <span>'[a-zA-Z]'</span> | cut <span>-f</span>2 <span>-d</span><span>' '</span>;; handled_connections) <span>echo</span><span>"<span>$NGINX_STATS</span>"</span> | grep -Ev <span>'[a-zA-Z]'</span> | cut <span>-f</span>3 <span>-d</span><span>' '</span>;; handled_requests) <span>echo</span><span>"<span>$NGINX_STATS</span>"</span> | grep -Ev <span>'[a-zA-Z]'</span> | cut <span>-f</span>4 <span>-d</span><span>' '</span>;; reading) <span>echo</span><span>"<span>$NGINX_STATS</span>"</span> | tail -<span>1</span> | cut <span>-f</span>2 <span>-d</span><span>' '</span>;; writing) <span>echo</span><span>"<span>$NGINX_STATS</span>"</span> | tail -<span>1</span> | cut <span>-f</span>4 <span>-d</span><span>' '</span>;; waiting) <span>echo</span><span>"<span>$NGINX_STATS</span>"</span> | tail -<span>1</span> | cut <span>-f</span>6 <span>-d</span><span>' '</span>;; *) <span>echo</span><span>$ERROR_WRONG_PARAM</span>; <span>exit</span><span>1</span>;; <span>esac</span><span>exit</span><span>0</span></code>
- agent的配置文件
/etc/zabbix/zabbix_agentd.conf
中定义了其他key的包含目录Include=/etc/zabbix/zabbix_agentd.d/
, 如果没有这个配置请自己添加下。接着在/etc/zabbix/zabbix_agentd.d/
目录新建一个文件nginx-params.conf
, 内容如下
<code>UserParameter=nginx[*],/usr/local/zabbix-agent/scripts/nginx-check.sh <span>"<span>$1</span>"</span></code>
- 重启agent
<code>>>> <span>/etc/init</span>.d/zabbix-agent restart</code>
Server 的Web端
首先命令行测试下刚才agent好使不,确认好用之后在web端导入模板,之后就可以给对应主机添加监控喽。
<code><span>>>></span> zabbix_get <span>-s</span><span>127.0</span><span>.0</span><span>.1</span><span>-p</span><span>10050</span><span>-k</span><span>"nginx[reading]"</span><span>0</span></code>
登录Zabbix3.0 的web界面,一次选择 Configuration
> Templates
, 在主界面的右上角有个 Import
按钮,用来导入模板。
模板文件比较长留一个下载地址
导入之后就可以给主机添加监控啦。
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });以上就介绍了[Zabbix30 ]添加Nginx监控,包括了zabbix,nginx方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

To allow the Tomcat server to access the external network, you need to: modify the Tomcat configuration file to allow external connections. Add a firewall rule to allow access to the Tomcat server port. Create a DNS record pointing the domain name to the Tomcat server public IP. Optional: Use a reverse proxy to improve security and performance. Optional: Set up HTTPS for increased security.

The start and stop commands of Nginx are nginx and nginx -s quit respectively. The start command starts the server directly, while the stop command gracefully shuts down the server, allowing all current requests to be processed. Other available stop signals include stop and reload.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

To register for phpMyAdmin, you need to first create a MySQL user and grant permissions to it, then download, install and configure phpMyAdmin, and finally log in to phpMyAdmin to manage the database.

Server deployment steps for a Node.js project: Prepare the deployment environment: obtain server access, install Node.js, set up a Git repository. Build the application: Use npm run build to generate deployable code and dependencies. Upload code to the server: via Git or File Transfer Protocol. Install dependencies: SSH into the server and use npm install to install application dependencies. Start the application: Use a command such as node index.js to start the application, or use a process manager such as pm2. Configure a reverse proxy (optional): Use a reverse proxy such as Nginx or Apache to route traffic to your application

To solve the "Welcome to nginx!" error, you need to check the virtual host configuration, enable the virtual host, reload Nginx, if the virtual host configuration file cannot be found, create a default page and reload Nginx, then the error message will disappear and the website will be normal show.

nginx appears when accessing a website. The reasons may be: server maintenance, busy server, browser cache, DNS issues, firewall blocking, website misconfiguration, network connection issues, or the website is down. Try the following solutions: wait for maintenance to end, visit during off-peak hours, clear your browser cache, flush your DNS cache, disable firewall or antivirus software, contact the site administrator, check your network connection, or use a search engine or web archive to find another copy of the site. If the problem persists, please contact the site administrator.

There are five methods for container communication in the Docker environment: shared network, Docker Compose, network proxy, shared volume, and message queue. Depending on your isolation and security needs, choose the most appropriate communication method, such as leveraging Docker Compose to simplify connections or using a network proxy to increase isolation.
