zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    2014 年最热门的国人开发开源软件TOP 100
    欢迎访问李培冠博客
    Go语言学习之路(持续更新)
    租房项目 获取地区信息服务
    租房项目 启动前的处理
    一步步带你用 FastDFS 搭建文件管理系统 详细的不得鸟
    golang 两个go程轮流打印一个切片
    golang 拷贝大切片一定比小切片代价大吗
    matlab 如何把数组A中与数组B中元素相同的元素删除
    golang 如何翻转含有中文 数字 英文字母等任意字符串
  • 原文地址:https://www.cnblogs.com/fangdecheng/p/9839577.html
Copyright © 2011-2022 走看看