参考文档:

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. Maven - pom中的<repository> <pluginRepositories>

    总结: <repository> 允许我们可以在POM中配置其它的远程仓库.这样做的原因有很多,比如你有一个局域网的远程仓库,使用该仓库能大大提高下载速度,继而提高构建速度,也有可能你依赖 ...

  2. 「luogu2387」[NOI2014] 魔法森林

    「luogu2387」[NOI2014] 魔法森林 题目大意 \(n\) 个点 \(m\) 条边的无向图,每条边上有两个权值 \(a,b\),求从 \(1\) 节点到 \(n\) 节点 \(max\{ ...

  3. django 模型models

    1. django 模型models 常用字段          1.models.AutoField 自增列 = int(11) 如果没有的话,默认会生成一个名称为 id 的列 如果要显式的自定义一 ...

  4. 题解 P4093 【[HEOI2016/TJOI2016]序列】

    这道题原来很水的? noteskey 一开始以为是顺序的 m 个修改,然后选出一段最长子序列使得每次修改后都满足不降 这 TM 根本不可做啊! 于是就去看题解了,然后看到转移要满足的条件的我发出了黑人 ...

  5. react給變量賦值并列元素

    今天在使用react時發現一個問題:我在給一個變量賦值多個元素,但不能用div包含起來. 如: var p = <div> <p></p> <p>< ...

  6. MVC或WebAPI发布后报错404问题的总结

    在MVC项目或者webAPI项目发布之后有时会发生404错误.针对这种错误的解决办法: 解决办法1(不推荐):在webconfig中 <system.webServer> 节点下 添加 & ...

  7. #10038.A Horrible Poem

    #10038.A Horrible Poem 题目传送门 思路解析 既然这道题目在hash板块里,那么自然就可以想到用hash做这道题目. 首先我们可以用hash数组存储字符串的前缀的hash值. 因 ...

  8. uitramon 安装包

    链接地址  密码:kkkk displayfintion :https://blog.csdn.net/JianJuly/article/details/80559933 密码:gn8p

  9. python正则表达式基础,以及pattern.match(),re.match(),pattern.search(),re.search()方法的使用和区别

    正则表达式(regular expression)是一个特殊的字符序列,描述了一种字符串匹配的模式,可以用来检查一个字符串是否含有某种子字符串. 将匹配的子字符串替换或者从某个字符串中取出符合某个条件 ...

  10. linux 磁盘io监控

    我们在线上linux服务器排查问题时,一般会通过top.free.netstat.df -h等命令排查cpu.内存.网络和磁盘等问题.有的时候我们需要更进一步了解磁盘io的使用情况,那么本文就是重点讲 ...