Prometheus nginx-vts-exporter 监控 Nginx

网友投稿 1720 2022-11-30

Prometheus nginx-vts-exporter 监控 Nginx

Prometheus nginx-vts-exporter 监控 Nginx

nginx-module-vts模块安装(模块编译进nginx)

# -最新的nginx-vts模块

wget src]# pwd/usr/src[root@localhost src]# lsdebug kernels nginx-1.16.1 nginx-1.16.1.tar.gz nginx-module-vts-0.1.18 v0.1.18.tar.gz

# nginx-module-vts安装

#重新编译cd nginx-1.16.1./configure --prefix=/usr/local/nginx --add-module=/usr/local/nginx-module-vts/–add-module=/usr/local/nginx-module-vts 为模块地址[root@localhost ~]# /usr/local/nginx/sbin/nginx -Vnginx version: nginx/1.16.1built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) configure arguments: --prefix=/usr/local/nginx --add-module=/usr/src/nginx-module-vts-0.1.18/

nginx配置

nginx配置server中添加:

location /status { vhost_traffic_status_display; vhost_traffic_status_display_format html; }

如果需要限制访问,可以使用

# vhost配置cat nginx-vts.confserver { listen 50001; server_name localhost; location /status { #allow 127.0.0.1; #替换为你的prometheus ip; #deny all; vhost_traffic_status_display; vhost_traffic_status_display_format html; }}

nginx.conf 配置cat nginx.conf{... # nginx-vts vhost_traffic_status_zone; vhost_traffic_status_filter_by_host on; #开启此功能,会根据不同的server_name进行流量的统计,否则默认会把流量全部计算到第一个上。 vhost_traffic_status_filter on; vhost_traffic_status_filter_by_set_key $status $server_name;...}

配置

如果想统计所有的虚拟主机,就在配置说明:

添加在nginx.conf中的on;​​

​​vhost_traffic_status_filter_by_set_key $status $server_name;​​

开启URL统计

​​vhost_traffic_status_filter on;​​

​​vhost_traffic_status_filter_by_set_key $uri uris::$server_name;​​

配置建议:

1.打开vhost过滤:

vhost_traffic_status_filter_by_host on; 开启此功能,在Nginx配置有多个server_name的情况下,会根据不同的server_name进行流量的统计,否则默认会把流量全部计算到第一个server_name上。 在不想统计流量的server区域禁用vhost_traffic_status,配置示例

server {...vhost_traffic_status off;...}

2.假如nginx没有规范配置server_name或者无需进行监控的server上,那么建议在此vhost上禁用统计监控功能。否则会出现“127.0.0.1”,hostname等的域名监控信息。 重新加载配置

/usr/local/nginx/sbin/nginx -s reload

完成以上步骤可以访问:​​ -zxvf nginx-vts-exporter-0.9.1.linux-amd64.tar.gzmv nginx-vts-exporter-0.9.1.linux-amd64 /usr/local/nginx-vts-exporter

使用systemctl 管理nginx-vts-exporter进程。

vim /usr/lib/systemd/system/nginx_vts_exporter.service[Unit]Description=prometheus_nginx_vtsAfter=network.target[Service]Type=simpleExecStart=/usr/local/nginx-vts-exporter/nginx-vts-exporter -nginx.scrape_uri daemon-reloadsystemctl enable nginx_vts_exportersystemctl start nginx_vts_exportersystemctl status nginx_vts_exporter

nginx-vts-exporter 抓取vts数据传向prometheus

prometheus 配置

#添加个节点 - job_name: 'nginx' static_configs: - targets: ['192.168.179.99:9913'][root@localhost prometheus]# ./promtool check config prometheus.yml Checking prometheus.yml SUCCESS: 1 rule files foundChecking rules/node.yml SUCCESS: 1 rules found

**重启prometheus **

[root@localhost prometheus]# ps -ef | grep promeroot 52211 1 0 06:20 ? 00:01:37 /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml[root@localhost prometheus]# kill -HUP 52211

grafana展示

导入模板2949

nginx监控指标说明

指标                                                                                   说明 nginx_server_requests                        统计nginx各个host 各个请求的总数,精确到状态码 nginx_upstream_requests                   统计各个upstream 请求总数,精确到状态码 nginx_server_connections                  统计nginx几种连接状态type的连接数 nginx_server_cache                           统计nginx缓存计算器,精确到每一种状态和转发type nginx_server_bytes                            统计nginx进出的字节计数可以精确到每个host,in进,out出 nginx_upstream_bytes                       统计nginx各个 upstream 分组的字节总数,细分到进出 nginx_upstream_responseMsec        统计各个upstream 平均响应时长,精确到每个节点

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:设计模式(七)--建造者模式
下一篇:Linux 一篇文章带你循序渐进top命令
相关文章

 发表评论

暂时没有评论,来抢沙发吧~