


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

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc


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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 English version
Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function
