监控软件运行状态

监控软件运行状态,第1张

zabbix监控nginx性能状态

Nginx在生产环境中应用广泛,因此有必要对nginx的性能进行监控,以发现问题。Zabbix监控nginx,首先确认nginx的监控指标,包括:基本活动指标,错误指标,性能指标。

nginx处理流程图如下:

注意:接受、已处理和请求是一直在增加的计数器。活动、等待、读取和写入随着请求的数量而增加或减少。


名称

形容

变址类型

接受

NGINX接受的客户端连接数

资源:功能

已处理(已处理)

成功的客户端连接。

资源:功能

活动

当前活动客户端连接数

资源:功能

已丢弃(已丢弃,已计算)

丢弃的连接数(已接受-已处理)

工作:错误*

个请求(请求数)

客户请求

工作:吞吐量


当INXworker进程接受来自OS的连接请求时,Accepts计数器递增,而当实际请求被连接(通过建立新的连接或重用空idle)时,Handled为。这两个计数器的值通常是相同的。如果它们不同,则表明连接已断开。这通常是由于资源限制,例如已经达到NGINX的worker_connections限制。

首先,nginx需要配置nginx_status。具体步骤是:在zabbixagentd客户端上,检查nginx是否加载了-http_stub_status_module。Zabbix根据nginx的存根状态模块监控nginx,并捕获状态模块提供的数据。如果之前没有打开过,现在想启用StubStatus模块,那么在编译nginx的时候要用-http_stub_status_module添加参数,并执行。/配置&&Make就可以了,不需要makeinstall,一般都是安装的。具体安装配置如下


(a)配置nginx

1.检查nginx_status是否开启,并检查是否开启。

[root@iZ237lzm354Z scripts]# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.4.7 built by gcc 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC)  TLS SNI support enabled configure arguments: --with-http_stub_status_module --with-http_ssl_module --with-pcre  --with-http_realip_module --with-http_image_filter_module [root@iZ237lzm354Z scripts]#

2.打开nginx_status的步骤:

[root@iZ237lzm354Z scripts]# vim /usr/local/nginx/conf/nginx.conf  server {                         listen       80 ;                         server_name  www.baidu.com;             rewrite ^/invitejoin/(.*)\.htm[l]?$  /register.shtml?$1 last;                   index index.jsp index.html;                  root /opt/home;             location = /nginx-status {                               stub_status on;                               access_log  off;                               allow 127.0.0.1;                               allow 10.253.12.34;                               ####zabbix服务器端的IP地址一般为内网IP                                }

3.测试并启动nginx

[root@iZ237lzm354Z脚本]#/usr/local/nginx/sbin/nginx-t

nginx:配置文件/usr/local/nginx/conf/nginx.conf语法没问题

nginx:配置文件/usr/local/nginx/conf/nginx.conf测试成功

[root@iZ237lzm354Z脚本]#/usr/local/nginx/sbin/nginx-sreload

4.卷曲测试:

[root@iZ237lzm354Z scripts]# curl www.baidu.com/nginx-status Active connections: 979  server accepts handled requests  756072922 756072922 1136799890  Reading: 0 Writing: 4 Waiting: 975

备注:

活动连接数–当前活动连接数
服务器接受已处理的请求–总共处理了756,072,922个连接,并成功创建了756,072,922次握手。总共处理了1,136,799,890个请求
读取-读取客户端的连接数量。
writing—等待的客户端响应数据的数量
当keep-alive打开时,该值等于active-(read+write),这意味着Nginx已经处理完了等待下一条请求指令的那些。


(2)配置zabbix_agentd

1、写足迹获取nginx的相关信息

[root@ittestserver1 opt]# vim /usr/local/zabbix/scripts/nginx-check_performance.sh  #!/bin/bash ################################## # Zabbix monitoring script # # nginx: # - anything available via nginx stub-status module # ################################## # Contact: # [email protected] # Zabbix requested parameter ZBX_REQ_DATA="$1" ZBX_REQ_DATA_URL="$2" # Nginx defaults NGINX_STATUS_DEFAULT_URL="www.baidu.com/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 [root@ittestserver1 opt]# chmod +x /usr/local/zabbix/scripts/nginx-check_performance.sh -rw-r--r-x1 root root 1645 2月 4 14:26/usr/local/zabbix/scripts/nginx-check_performance.sh


2.配置zabbix_agentd.conf启用UserParameter并配置相关参数。

[root@ittestserver1 opt]# vim /usr/local/zabbix/etc/zabbix_agentd.conf ####### USER-DEFINED MONITORED PARAMETERS ####### ### Option: UnsafeUserParameters #       Allow all characters to be passed in arguments to user-defined parameters. #       The following characters are not allowed: #       \ ' " ` * ? [ ] { } ~ $ ! & ; ( ) < > | # @ #       Additionally, newline characters are not allowed. #       0 - do not allow #       1 - allow # # Mandatory: no # Range: 0-1 # Default: # UnsafeUserParameters=0 UnsafeUserParameters=1 ### Option: UserParameter #       User-defined parameter to monitor. There can be several user-defined parameters. #       Format: UserParameter=<key>,<shell command> #       See 'zabbix_agentd' directory for examples. # # Mandatory: no # Default: # UserParameter= UserParameter=nginx[*],/usr/local/zabbix/scripts/nginx-check_performance.sh "$1"


3.重启zabbix_agentd客户端

[root@zabbix ~]# /etc/init.d/zabbix_agentd restart Shutting down zabbix_agentd:                               [  OK  ] Starting zabbix_agentd:                                    [  OK  ] [root@zabbix ~]#

4.在zabbix服务器上测试。

[root@zabbix ~]# zabbix_get -s 10.253.17.20 -p 10050 -k "nginx[reading]" 0 [root@zabbix ~]#


(3)在网页上配置nginx模板的相关监控。

1.登录zabbix界面,点击:配置)-模板)-导入


2.给主机添加模板:选择主机-nginx服务器主机-模板-选择(刚导入的nginx性能状态的模板)-添加-更新。


3.查看nginx监控的最新数据:监控-图形-选择对应的监控类型。



备注:

活动:当前活动的连接数。

接受:接受的请求数

已处理:已处理的请求数(正常的服务器响应,这两项应该相等)

Requests:客户端处理的请求数。(吞吐量)

读取:当接收到请求时,连接离开等待状态,请求本身增加读取状态计数。在这种状态下,NGINX将读取客户端请求头。请求头相对较小,因此这通常是一个快速 *** 作。

写入:读取请求后,它增加写入状态计数,并保持该状态,直到响应返回给客户端。这意味着当请求处于写状态时,一方面NGINX等待来自上游系统的结果(系统被放在NGINX的“后面”),另一方面NGINX也同时响应。请求经常花费大量时间处于写状态。

等待:如果此时没有活动请求,活动连接也可以处于等待子状态。新的连接可以绕过这个状态,直接改变到读取状态。最常见的情况是使用“接受过滤器”和“延迟接受”时。在这种情况下,NGINX不会收到来自工作进程的通知,直到它有足够的数据开始响应。如果连接被设置为保持活动,它将在发送响应后等待。


请参考:https://github.com/oscm/zabbix/tree/master/nginx.

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/777869.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-03
下一篇 2022-05-03

发表评论

登录后才能评论

评论列表(0条)

保存