• Zabbix监控nginx


    netstat -lnpt               //查看有没有80端口

    上传rpm包

    rpm -ivh nginx-1.15.9-1.x86_64.rpm            //安装nginx的rpm包

    查看一下nginx

    nginx -V

     vim /usr/local/nginx/conf/nginx.conf        //修改nginx配置文件

    添加内容;

    location /status {
    stub_status on;
    access_log off;;

    }

       killall -HUP nginx

    【假如没有killall命令  安装psmisc】

    使用脚本采集信息

    在anget端操作:

    cd /usr/local/zabbix/

    mkdir scripts  

    vim scripts/nginx-check.sh

    脚本内容:

    #/bin/bash
    ########################### 

    #zabbix monitoring script
    #
    # nginx:
    # - anything available via nginx stub-status module
    #
    ##################################
    # Contact:
    # vincent.viallet@gmail.com
    # Zabbix requested parameter
    ZBX_REQ_DATA="$1"
    ZBX_REQ_DATA_URL="$2"
    # Nginx defaults
    NGINX_STATUS_DEFAULT_URL="192.168.96.4/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

    ===========================================================

    chmod +x scripts/nginx-check.sh        //脚本添加可执行权限

    修改nginx端配置文件

    vim /usr/local/zabbix/etc/zabbix_agentd.conf

    内容:

    LogFile=/tmp/zabbix_agentd.log
    Server=192.168.96.5
    ServerActive=192.168.96.5
    Hostname=agent.zabbix.com
    UnsafeUserParameters=1
    UserParameter=nginx[*],/usr/local/zabbix/scripts/nginx-check.sh "$1"

    重启agentd

    /etc/init.d/zabbix_agentd restart

    netstat -anpt | grep 10050

    在server端获取信息

    /usr/local/zabbix/bin/zabbix_get -s 192.168.96.6 -p 10050 -k "nginx[reading]"

     /usr/local/zabbix/bin/zabbix_get -s 192.168.96.6 -p 10050 -k "nginx[waiting]"

     Web  Zabbix  端添加主机:

    配置——模板——导入模板——主机——agent.zabbix.com——模板——选择模板——添加——更新

  • 相关阅读:
    WPF TextBox 一些设置技巧
    Rust 初始配置
    Framework​Element.​Find​Name 根据名字查找控件
    C# SQLite 数据库操作
    MP3 信息读取
    C# event 事件学习
    Nginx 整合 Lua 实现动态生成缩略图
    Spring Cloud 入门 之 Config 篇(六)
    Spring Cloud 入门 之 Zuul 篇(五)
    Flyway 简单入门教程
  • 原文地址:https://www.cnblogs.com/XXXX001/p/11800870.html
Copyright © 2020-2023  润新知