参考文档:

https://blog.51cto.com/xujpxm/2080146

注: 本文留用自己参考,建议看以上参考文档,更为细致

prometheus 监控 nginx 使用 nginx-vts-exporter 采集数据。同时,需要 nginx 支持 nginx-module-vts 模块获取 nginx 自身的一些数据。

nginx 的模块支持

进入nginx 安装包解压后的目录,下载模块文件

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

编译安装,只需要在之前的编译参数中加上 --add-module=/path/to/nginx-module-vts 即可

./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx  --conf-path=/usr/local/nginx/conf/nginx.conf --user=nginx --group=nginx --add-module=./nginx-module-vts
make && make install

修改nginx 配置

http {
vhost_traffic_status_zone;
vhost_traffic_status_filter_by_host on; #开启此功能,会根据不同的server_name进行流量的统计,否则默认会把流量全部计算到第一个上。
...
server {
listen 1212;
allow 127.0.0.1;
allow prometheus_server_ip; #替换为你的prometheus ip; location /nginx-status {
stub_status on;
access_log off;
}
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
}
}

在不想统计流量的server 区域(未规范配置server_name或者无需进行监控的server上)可以禁用 vhost_traffic_status:

server {
vhost_traffic_status off;
...
}

数据展示

curl 127.0.0.1:1212/nginx-status



说明:(此处说明参考https://blog.csdn.net/ly_dengle/article/details/78792812)

Active connections: 当前nginx正在处理的活动连接数.

Server accepts handled requests: nginx启动以来总共处理了52783270 个连接,成功创建52783270 握手(证明中间没有失败的),总共处理了136279681 个请求。

Reading: nginx读取到客户端的Header信息数.

Writing: nginx返回给客户端的Header信息数.

Waiting: 开启keep-alive的情况下,这个值等于 active – (reading + writing),意思就是nginx已经处理完成,正在等候下一次请求指令的驻留连接。

所以,在访问效率高,请求很快被处理完毕的情况下,Waiting数比较多是正常的.如果reading +writing数较多,则说明并发访问量非常大,正在处理过程中。

访问http://127.0.0.1:1212/status,可以得到各种参数



访问 http://127.0.0.1:1212/status/format/prometheus 可直接获取prometheus格式的监控数据。

访问 http://127.0.0.1:1212/status/format/json 可直接获取json格式的监控数据。

接入prometheus

接入prometheus有两种方式:

直接用nginx-vts-exporter数据源 和 nginx-vts-exporter 抓取vts数据传向prometheus

nginx-vts-exporter数据源

将http://127.0.0.1:1212/status/format/prometheus数据源直接接入prometheus

vim /usr/local/prometheus/prometheus.yml
- job_name: 'vts'
metrics_path: /status/format/prometheus
file_sd_configs:
- refresh_interval: 1m
files:
- "targets/vts.json" cat targets/vts.json
[
{
"labels": {
"machine_room": "roomone",
"job": "proxyone",
"type": "vts"
},
"targets": [
"1.1.1.1:1212",
"1.1.1.2:1212"
]
},
{
"labels": {
"machine_room": "roomtwo",
"job": "proxytwo",
"type": "vts"
},
"targets": [
"1.1.2.1:1212",
"1.1.2.2:1212"
]
}
]

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

nginx-vts-exporter 安装使用

wget -c https://github.com/hnlq715/nginx-vts-exporter/releases/download/v0.9.1/nginx-vts-exporter-0.9.1.linux-amd64.tar.gz
tar -xvf nginx-vts-exporter-0.9.1.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/nginx-vts-exporter-0.9.1.linux-amd64/
./nginx-vts-exporter -nginx.scrape_uri http://127.0.0.1:1212/status/format/json &

端口为9913,查看数据:

curl http://127.0.0.1:9913/metrics > nginx_data

在Prometheus中添加此target 便可接入。

常用监控规则:

求Nginx的QPS:

sum(irate(nginx_server_requests{code="total",host=~"$DomainName"}[5m]))

求4xx万分率(5xx类似,code=“5xx”):

(sum(irate(nginx_server_requests{code="4xx",host=~"$DomainName"}[5m])) / sum(irate(nginx_server_requests{code="total",host=~"$DomainName"}[5m]))) * 10000

求upstream的QPS(示例求group1的qps):

sum(irate(nginx_upstream_requests{code="total",upstream="group1"}[5m]))

求upstream后端server的响应时间(示例求group1的后端响应时间):

nginx_upstream_responseMsec{upstream=“group1”}

prometheus — nginx-vts-exporter的更多相关文章

  1. Prometheus 集成 Node Exporter

    文章首发于公众号<程序员果果> 地址:https://mp.weixin.qq.com/s/40ULB9UWbXVA21MxqnjBxw 简介 Prometheus 官方和一些第三方,已经 ...

  2. 实战 Prometheus 搭建监控系统

    实战 Prometheus 搭建监控系统 Prometheus 是一款基于时序数据库的开源监控告警系统,说起 Prometheus 则不得不提 SoundCloud,这是一个在线音乐分享的平台,类似于 ...

  3. prometheus(1)之核心概念

    个人理解:prometheus核心在于 1.prom数据类型的理解 (4钟数据类型 与常用的promQL语法 其实很容易) 2.各种服务发现与正则拼接(服务发现的拼接其实官方定义好的 理解就行) 3. ...

  4. 05 . Prometheus监控Nginx

    List CentOS7.3 prometheus-2.2.1.linux-amd64.tar.gz nginx-module-vts 节点名 IP 软件版本 硬件 网络 说明 Prometheus ...

  5. Prometheus监控Nginx

    转载自:https://www.cnblogs.com/you-men/p/13173245.html CentOS7.3 prometheus-2.2.1.linux-amd64.tar.gz ng ...

  6. Docker系列(11)- 部署Nginx

    step-1 搜索镜像 使用search命令,建议去dockerhub上搜索,可以看到帮助文档 [root@localhost ~]# docker search nginx NAME DESCRIP ...

  7. 监控prometheus

    一.prometheus-webhook-daingtalak github地址:[Releases · timonwong/prometheus-webhook-dingtalk · GitHub] ...

  8. Kubernetes容器集群管理环境 - Prometheus监控篇

    一.Prometheus介绍之前已经详细介绍了Kubernetes集群部署篇,今天这里重点说下Kubernetes监控方案-Prometheus+Grafana.Prometheus(普罗米修斯)是一 ...

  9. Kubernetes 系列(五):Prometheus监控框架简介

    由于容器化和微服务的大力发展,Kubernetes基本已经统一了容器管理方案,当我们使用Kubernetes来进行容器化管理的时候,全面监控Kubernetes也就成了我们第一个需要探索的问题.我们需 ...

  10. 如何利用Prometheus监控你的应用

    Prometheus作为一套完整的开源监控接近方案,因为其诸多强大的特性以及生态的开放性,俨然已经成为了监控领域的事实标准并在全球范围内得到了广泛的部署应用.那么应该如何利用Prometheus对我们 ...

随机推荐

  1. 游记-HNOI2019

    Day -1 最后一场考试依旧没有ak(达成成就:\(\mathrm{OI}\) 生涯 AK 次数仅一次) Day 0 听dalao们说现在做题已经没有意义了,不如多口胡几道题,拓展视野 虽然很抗拒但 ...

  2. python正则表达式--match search方法

    1.re.match函数 re.match 尝试从字符串的起始位置匹配一个模式,如果不是起始位置匹配成功的话,match()就返回None. (1)函数语法: re.match(pattern, st ...

  3. python socket.error: [Errno 24] Too many open files

    以openwrt AR9331开发板为例,socket连接到1019个就报错 “python socket.error: [Errno 24] Too many open files” 1.查看开发板 ...

  4. vertx的ShardData共享数据

    数据类型 一共4种 synchronous shared maps (local) asynchronous maps (local or cluster-wide) asynchronous loc ...

  5. Django—跨域请求(jsonp)

    同源策略 如果两个页面的协议,端口(如果有指定)和域名都相同,则两个页面具有相同的源. 示例:两个Django demo demo1 url.py url(r'^demo1/',demo1), vie ...

  6. 控制可编辑的Div 在添加图片,或者@某人的时候 光标移动到最后

    this.$refs.editor.innerHTML += '<span style="color:yellowgreen;">@ 野猪佩奇</span> ...

  7. 2018-2019-2 网络对抗技术 20165328 Exp4 恶意代码分析

    实验内容: 系统运行监控(2分) 使用如计划任务,每隔一分钟记录自己的电脑有哪些程序在联网,连接的外部IP是哪里.运行一段时间并分析该文件,综述一下分析结果.目标就是找出所有连网的程序,连了哪里,大约 ...

  8. Jmeter(1)介绍

    JMeter是什么东西 Jmeter(Apache JMeter)是一个100%基于JAVA的应用程序,它的功能是 分析和衡量 web应用程序和各种服务的性能和负载能力 Jmeter不是一个浏览器,它 ...

  9. 「LibreOJ Round #9」CommonAnts 的调和数

    题解: 对于subtask3:可以把相同的归在一起就是$nlogn$的了 对于subtask4: 可以使用高维前缀和的技术,具体的就是把每个质因数看作一维空间 那么时间复杂度是$\sum \limit ...

  10. Python 官方文档解读(2):threading 模块

    使用 Python 可以编写多线程程序,注意,这并不是说程序能在多个 CPU 核上跑.如果你想这么做,可以看看关于 Python 并行计算的,比如官方 Wiki. Python 线程的主要应用场景是一 ...