zoukankan      html  css  js  c++  java
  • Prometheus监控Nginx

    在k8s的master节点安装nginx-module-vts模块

    解压软件包

    unzip nginx-module-vts-master.zip
    mv nginx-module-vts-master /usr/local/
    

     安装nginx

    tar zxvf nginx-1.15.7.tar.gz
    
    ./configure  --prefix=/usr/local/nginx --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module 
    --with-pcre --with-file-aio --with-http_realip_module --add-module=/usr/local/nginx-module-vts-master

    编译和编译安装

    make && make install

    修改nginx配置文件

    cat  /usr/local/nginx/conf/nginx.conf

    server下添加如下:

    location /status {
            vhost_traffic_status_display;
            vhost_traffic_status_display_format html;
            }
    

     http中添加如下

    vhost_traffic_status_zone;
    

     测试nginx配置文件是否正确

    /usr/local/nginx/sbin/nginx -t
    

    如果正确没问题,启动nginx

    启动nginx:

    /usr/local/nginx/sbin/nginx
    

     访问k8s的master节点主机ip/status可以看到nginx监控数据

    安装nginx-vts-exporter

    解压软件包

    unzip  nginx-vts-exporter-0.5.zip
    

     启动服务

    mv nginx-vts-exporter-0.5  /usr/local/
    chmod +x /usr/local/nginx-vts-exporter-0.5/bin/nginx-vts-exporter

     cd /usr/local/nginx-vts-exporter-0.5/bin

    nohup ./nginx-vts-exporter  -nginx.scrape_uri http://192.168.124.16/status/format/json &
    

     #注意:http://192.168.124.16/status/format/json这个地方的ip地址是nginx服务所在主机的IP地址,nginx-vts-exporter的监听端口是9913

    修改prometheus-cfg.yaml文件

    添加如下job:

    - job_name: 'nginx'
    scrape_interval: 5s
    static_configs:
    - targets: ['192.168.124.16:9913']
    kubectl apply -f prometheus-cfg.yaml
    kubectl delete -f prometheus-deploy.yaml
    kubectl apply -f prometheus-deploy.yaml

    #注意:

    - targets: ['192.168.124.16:9913']这个ip地址是nginx-vts-exporter程序所在机器的ip地址

    在grafana界面导入nginx图表

     https://mp.weixin.qq.com/s/SP3r8a6I7wNwfWB9hI5SIg

  • 相关阅读:
    省选测试42
    省选测试41
    省选测试40
    省选测试39
    python海龟画图生成星星
    Python-列表简介
    Linux系统中设置默认的Java版本
    虚拟机无线网卡桥接失败
    pycharm设置启动图标
    禁用vscode硬件加速
  • 原文地址:https://www.cnblogs.com/zjz20/p/13222817.html
Copyright © 2011-2022 走看看