参考文档:

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. C# - 设计模式 - 虚模式

    虚模式 问题场景 子类从抽象派生是为了解耦,但为了适应新的变化,可能需要向抽象类添加新功能,假如在添加新功能之前已经有100个子类实现了抽象,那么接下来你得在100个子类中去重写向抽象添加的新功能. ...

  2. php 进行跨域操作

    本地配置两个域名: http://www.concent.com   主域名 http://s.concent.com/       子域名 在主域名下添加跨域代码: ini_set('session ...

  3. WebApi-1 与MVC路由机制比较

    在MVC里面,默认路由机制是通过url路径去匹配对应的action方法 public class RouteConfig { public static void RegisterRoutes(Rou ...

  4. 详解MariaDB数据库的触发器

    1.什么是触发器 触发器是一种特殊的存储过程,它在插入,删除或修改特定表中的数据时触发执行 它比数据库本身标准的功能有更精细和更复杂的数据控制能力 2.触发器的作用: 2.1 安全性 可以基于数据库的 ...

  5. 初识C语言(三)

    C语言中的运算符 C语言中的运算就是对数据进行操作.处理的过程.运算符就是指定该运算的处理方式. C语言中的运算符: 算术运算符 赋值运算符 关系运算符 逻辑运算符 三目运算符 算数运算符 C语言中的 ...

  6. 主席树套树状数组——带修区间第k大zoj2112

    主席树带修第k大 https://www.cnblogs.com/Empress/p/4659824.html 讲的非常好的博客 首先按静态第k大建立起一组权值线段树(主席树) 然后现在要将第i个值从 ...

  7. 学习笔记_J2EE_SpringMVC_03_注解配置_@RequestMapping用法

    @RequestMappingde的用法 摘要: 主要介绍注解@RequestMapping的用法 一.@RequestMapping 简介 在Spring MVC 中使用 @RequestMappi ...

  8. JS & JQuery 动态处理select option

    原文 出处http://www.51xuediannao.com/html+css/htmlcssjq/cssbuhuanhang.html 今天你问了我一个关于在<select>里动态添 ...

  9. vue结构详解

    相关文件和文件夹的含义: build 文件夹: 里面是对 webpack 开发和打包的相关设置,包括入口文件.输出文件.使用的模块等:config 文件夹: 主要是指定开发和打包中的静态资源路径.要压 ...

  10. Chrome插件触发web页面的事件

    Chrome插件中不能直接调用Web页面的元素js,原因是chrome插件的机制http://stackoverflow.com/questions/17819344/triggering-a-cli ...