• Zabbix监控Nginx


    服务器系统角色IP
    CentOS 7.4 x86_64 Zabbix-Server 172.16.1.71
    CentOS 7.4 x86_64 Zabbix-Agent 172.16.1.7

    2. 在nginx.cong的Server标签下加入下面内容
    [root@web01 conf.d]# cat status.conf
    server {
    listen 80;
    server_name _;

    location /nginx_status {
    stub_status;
    access_log off;
    allow 127.0.0.1;
    deny all;
    }
    }

    3.本地访问Nginx Status

    [root@web01 conf.d]# curl http://127.0.0.1/nginx_status
    Active connections: 1
    server accepts handled requests
    255 255 252
    Reading: 0 Writing: 1 Waiting: 0

    4.编写Nginx的shell脚本

    [root@web01 ~]#  mkdir -p /etc/zabbix/scripts

    [root@web01 ~]# vim /etc/zabbix/scripts/nginx_status.sh

    #!/bin/bash

    NGINX_COMMAND=$1
    NGINX_PORT=80

    nginx_active(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Active/ {print $NF}'
    }

    nginx_reading(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Reading/ {print $2}'
    }

    nginx_writing(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Writing/ {print $4}'
    }

    nginx_waiting(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk '/Waiting/ {print $6}'
    }

    nginx_accepts(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $1}'
    }

    nginx_handled(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $2}'
    }

    nginx_requests(){
    /usr/bin/curl -s "http://127.0.0.1:"$NGINX_PORT"/nginx_status/" |awk 'NR==3 {print $3}'
    }


    case $NGINX_COMMAND in
    active|ACTIVE)
    nginx_active;
    ;;
    reading)
    nginx_reading;
    ;;
    writing)
    nginx_writing;
    ;;
    waiting)
    nginx_waiting;
    ;;
    accepts)
    nginx_accepts;
    ;;
    handled)
    nginx_handled;
    ;;
    requests)
    nginx_requests;
    ;;
    *)
    echo $"USAGE:$0 {active|reading|writing|waiting|accepts|handled|requests}"
    esac

    [root@web01 ~]# chmod +x  /etc/zabbix/zabbix_agentd.d/scripts/nginx_status.sh

    6.监控项 nginx_status.conf的配置文件如下:

    cat /etc/zabbix/zabbix_agentd.d/nginx.conf
    UserParameter=nginx_status[*],/bin/bash /etc/zabbix/zabbix_agentd.d/scripts/nginx_status.sh "$1"

    7.重启zabbix-agent

    systemctl restart zabbix-agent.service

    8.使用zabbix-get获取值

    [root@zabbix ~]# zabbix_get -s 172.16.1.7 -k nginx_status[handled]
    438

  • 相关阅读:
    run C source file like a script
    shared_ptr注意点
    C++ #if #endif #define #ifdef #ifndef #if defined #if !defined详解 (转)
    linux切换g++
    std::forward_list
    有关typename
    win7下 mysql安装(mysql-5.7.18-winx64.zip)
    c++ 库函数返回的字符串指针是否需要手动释放
    c++ const char *[] or char [][]
    校园资源助手
  • 原文地址:https://www.cnblogs.com/fangdecheng/p/9839577.html
Copyright © 2020-2023  润新知