图解一个客户端连接开源版本的Nginx情况

zabbix4.2学习笔记--监控nginx-LMLPHP

Accepts(接受)、Handled(已处理)、Requests(请求数)是一直在增加的计数器。Active(活跃)、Waiting(等待)、Reading(读)、Writing(写)随着请求量而增减。

环境

centos7.5192.168.181.135zabbix4.2服务端
centos7.5192.168.181.136zabbix4.2客户端

Nginx相关指标的收集

首先在nginx配置文件中打开stub_status功能,并通过nginx -s reload命令重新加载配置文件

vim /usr/local/nginx/conf/nginx.conf

server {
# zabbix监控nginx基本活跃指标
location /ngx_status {
stub_status on;
access_log off;
allow 192.168.181.0/24;
allow 127.0.0.1;
deny all;
} nginx -s reload

zabbix客户端配置脚本指令

cat /etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf

UserParameter=nginx.status[*],/etc/zabbix/scripts/ngx-status.sh $1

创建文件夹

mkdir /etc/zabbix/scripts

编辑ngx-status.sh脚本

#!/bin/bash

#########################################################################
# File Name: nginx.sh
# file_path:
# Author: 浪子尘心
# Mail: [email protected]
# Created Time: 2019-03-17 16:50:21
# Last Changed: 2019-03-17 16:52:06
# Description: zabbix 通过 status 模块监控 nginx
# Version:
######################################################################### ST="127.0.0.1"
PORT="80" # 检测nginx相关参数
case $1 in
ping)
result=`/bin/pidof nginx 2>/dev/null| wc -l`
echo $result
;;
active)
result=`/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'`
echo $result
;;
reading)
result=`/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'`
echo $result
;;
writing)
result=`/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'`
echo $result
;;
waiting)
result=`/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'`
echo $result
;;
accepts)
result=`/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $1}'`
echo $result
;;
handled)
result=`/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $2}'`
echo $result
;;
requests)
result=`/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $3}'`
echo $result
;;
dropped)
result=`/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $1-$2}'`
echo $result
;;
*)
echo "Usage:$0(ping|active|reading|writing|waiting|accepts|handled|requests|dropped)"
;;
esac

编辑完成添加执行权限并重启客户端

chmod +x /etc/zabbix/scripts/ngx-status.sh
systemctl restart zabbix-agent

zabbix页面导入模板

模板下载

模板下载完成之后,在zabbix页面点击导入模板,点击主机添加模板即可

zabbix4.2学习笔记--监控nginx-LMLPHP

zabbix4.2学习笔记--监控nginx-LMLPHP

05-01 23:23