


[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教程有兴趣的朋友有所帮助。

In PHP, trait is suitable for situations where method reuse is required but not suitable for inheritance. 1) Trait allows multiplexing methods in classes to avoid multiple inheritance complexity. 2) When using trait, you need to pay attention to method conflicts, which can be resolved through the alternative and as keywords. 3) Overuse of trait should be avoided and its single responsibility should be maintained to optimize performance and improve code maintainability.

Dependency Injection Container (DIC) is a tool that manages and provides object dependencies for use in PHP projects. The main benefits of DIC include: 1. Decoupling, making components independent, and the code is easy to maintain and test; 2. Flexibility, easy to replace or modify dependencies; 3. Testability, convenient for injecting mock objects for unit testing.

SplFixedArray is a fixed-size array in PHP, suitable for scenarios where high performance and low memory usage are required. 1) It needs to specify the size when creating to avoid the overhead caused by dynamic adjustment. 2) Based on C language array, directly operates memory and fast access speed. 3) Suitable for large-scale data processing and memory-sensitive environments, but it needs to be used with caution because its size is fixed.

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

In JavaScript, you can use NullCoalescingOperator(??) and NullCoalescingAssignmentOperator(??=). 1.??Returns the first non-null or non-undefined operand. 2.??= Assign the variable to the value of the right operand, but only if the variable is null or undefined. These operators simplify code logic, improve readability and performance.

CSP is important because it can prevent XSS attacks and limit resource loading, improving website security. 1.CSP is part of HTTP response headers, limiting malicious behavior through strict policies. 2. The basic usage is to only allow loading resources from the same origin. 3. Advanced usage can set more fine-grained strategies, such as allowing specific domain names to load scripts and styles. 4. Use Content-Security-Policy-Report-Only header to debug and optimize CSP policies.

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

HTTPS is a protocol that adds a security layer on the basis of HTTP, which mainly protects user privacy and data security through encrypted data. Its working principles include TLS handshake, certificate verification and encrypted communication. When implementing HTTPS, you need to pay attention to certificate management, performance impact and mixed content issues.


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

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment