zoukankan      html  css  js  c++  java
  • zabbix_nginx监控

    环境说明

    • 已关闭防火墙、selinux;
    • 所用zabbix版本4.0.3(源码安装);
    • 开启Nginx状态监测,开启配置详情请见Nginx状态监测;
    • 所用IP地址如下表:
    ip地址 角色
    192.168.163.128 server
    192.168.163.168 agent

    配置

    • 编写脚本
    #!/bin/bash
    
    NGINX_PORT=80
    NGINX_COMMON=$1
    
    function Active_connection () {
    curl -s http://127.0.0.1:$NGINX_PORT/status | awk '/Active/ {print NF}'
    }
    function accepts () {
    curl -s http://127.0.0.1:$NGINX_PORT/status | awk 'NR==3 {print $1}'
    }
    function handled () {
    curl -s http://127.0.0.1:$NGINX_PORT/status | awk 'NR==3 {print $2}'
    }
    function requests () {
    curl -s http://127.0.0.1:$NGINX_PORT/status | awk 'NR==3 {print $3}'
    }
    function Reading () {
    curl -s http://127.0.0.1:$NGINX_PORT/status | awk '/Reading/ {print $2}'
    }
    function Writing () {
    curl -s http://127.0.0.1:$NGINX_PORT/status | awk '/Writing/ {print $4}'
    }
    function Waiting () {
    curl -s http://127.0.0.1:$NGINX_PORT/status | awk '/Waiting/ {print $6}'
    }
    
    case $1 in
    	Active_connection)
    		Active_connection;
    	;;
    	requests)
    		requests;
    	;;
    	accepts)
    		accepts;
    	;;
    	handled)
    		handled;
    	;;
    	Reading)
    		Reading;
    	;;
    	Writing)
    		Writing;
    	;;
    	Waiting)
    		Waiting;
    	;;
    	*)
    		echo "Usage:$0 {Active_connection|requests|accepts|handled|Reading|Writing|Waiting}"
    	;;
    esac
    
    
    
    • 给脚本赋予执行权限
    [root@localhost scripts]# chmod +x nginx_status.sh
    
    • 修改配置文件/usr/local/etc/zabbix_agentd.conf
    UnsafeUserParameters=1
    UserParameter=nginx_status[*],/bin/bash /scripts/nginx_status.sh "$1"
    
    
    • 重启agent端zabbix-agent服务
    pkill zabbix_agentd
    zabbix_agentd
    
    
    • 在server端进行测试
    [root@localhost init.d]# zabbix_get -s 127.0.0.1 -k "nginx_status[requests]"
    481
    
    
  • 相关阅读:
    搭建 structs2 环境
    数据库基础
    好书推荐整理
    Java 完美判断中文字符
    中文在unicode中的编码范围
    [转载]爬虫的自我解剖(抓取网页HtmlUnit)
    web应用配置
    简单的Java Web服务器
    dos基本命令
    Unrecognized Windows Sockets error: 0: JVM_Bind
  • 原文地址:https://www.cnblogs.com/cljhfy/p/10998703.html
Copyright © 2011-2022 走看看