


[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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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





How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".
