prometheus监控NGINX

安装nginx-vts模块

git clone https://github.com/vozlt/nginx-module-vts 

./configure --prefix=/usr/local/nginx --add-module=/tmp/nginx-module-vts --with-pcre --user=daemon --group=daemon --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-stream --with-http_gzip_static_module
make && install

添加nginx配置文件,暴露监控指标

$ /usr/local/nginx/conf/nginx.conf
http {
    ...
    vhost_traffic_status_zone;
    ...
}

$ vim /usr/local/nginx/conf/vhost/nginx-vts-status.conf
server {        
    listen 8088;
    
    location /status {
        vhost_traffic_status_display;
        vhost_traffic_status_display_format html;
    }
    
}

#需要重启模块才能生效
$ /usr/local/nginx/sbin/nginx -s stop
$ /usr/local/nginx/sbin/nginx

然后访问ip:8088/status,可以看到下面的数据
在这里插入图片描述
部署nginx-vts-exporter
推荐docker方式

参考链接
https://github.com/hnlq715/nginx-vts-exporter/#download
docker pull sophos/nginx-vts-exporter
docker run  -ti --rm -p 9913:9913 --env NGINX_STATUS="http://10.98.2.60:8081/status/format/json" sophos/nginx-vts-exporter

注意8081是nginx的端口
默认端口为 :9913/metrics

在这里插入图片描述

配置prometheus

$ vim /usr/local/prometheus/prometheus.yml 
...
  - job_name: 'nginx-vts'
    static_configs:
    - targets:
      - 你的IPxxx:9913

重启生效  
promtool check config /usr/local/src/prometheus-2.17.1.linux-amd64/prometheus.yml
kill -HUP 765

配置grafana
导入模板: 2949
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值