GitHub上官方地址:https://github.com/knyar/nginx-lua-prometheus

告警规则地址:https://awesome-prometheus-alerts.grep.to/rules#nginx

1.nginx需要支持lua功能,若是使用openresty的话,则自带支持lua

2.把lua文件上传到服务器中,

3.修改nginx配置文件,加载lua功能

# cat nginx.conf
http { ...... lua_shared_dict prometheus_metrics 10M;
lua_package_path "/path/to/nginx-lua-prometheus/?.lua;;"; # lua文件存放路径
init_worker_by_lua_block {
prometheus = require("prometheus").init("prometheus_metrics")
metric_requests = prometheus:counter(
"nginx_http_requests_total", "Number of HTTP requests", {"host", "status"})
metric_latency = prometheus:histogram(
"nginx_http_request_duration_seconds", "HTTP request latency", {"host"})
metric_connections = prometheus:gauge(
"nginx_http_connections", "Number of HTTP connections", {"state"})
}
log_by_lua_block {
metric_requests:inc(1, {ngx.var.server_name, ngx.var.status})
metric_latency:observe(tonumber(ngx.var.request_time), {ngx.var.server_name})
} server { ......
# 设置prometheus收集收据接口
location /metrics {
content_by_lua_block {
metric_connections:set(ngx.var.connections_reading, {"reading"})
metric_connections:set(ngx.var.connections_waiting, {"waiting"})
metric_connections:set(ngx.var.connections_writing, {"writing"})
prometheus:collect()
}
}
} }

4.先检测nginx配置文件,然后重启nginx,访问 http://ip:port/metrics

5.修改prometheus配置文件,加上监听nginx的配置

  - job_name: 'nginx'
static_configs:
- targets: ['localhost:80']

6.把nginx告警规则放在prometheus指定目录下

重启prometheus

7.grafana使用的模板

模板ID:10223

地址:https://grafana.com/grafana/dashboards/10223

另一种方式,参考网址:https://www.cnblogs.com/you-men/p/13173245.html

用prometheus监控Nginx的更多相关文章

  1. Prometheus 监控 Nginx 流量 (三)

    介绍 基于Openresty和Prometheus.Consul.Grafana设计的,实现了针对域名和Endpoint级别的流量统计,使用Consul做服务发现.KV存储,Grafana做性能图展示 ...

  2. 05 . Prometheus监控Nginx

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

  3. Prometheus监控Nginx

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

  4. 基于k8s集群部署prometheus监控ingress nginx

    目录 基于k8s集群部署prometheus监控ingress nginx 1.背景和环境概述 2.修改prometheus配置 3.检查是否生效 4.配置grafana图形 基于k8s集群部署pro ...

  5. skipper prometheus 监控

    skipper 是支持prometheus监控的,只是没有启用,需要添加参数 -enable-prometheus-metrics 测试使用的是一个简单nginx web ,同时使用docker-co ...

  6. openresty(完整版)Lua拦截请求与响应信息日志收集及基于cjson和redis动态路径以及Prometheus监控(转)

    直接上文件 nginx.conf #运行用户和组,缺省为nobody,若改为别的用户和组,则需要先创建用户和组 #user wls81 wls; #开启进程数,一般与CPU核数等同 worker_pr ...

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

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

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

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

  9. Prometheus监控(二)

    Prometheus监控(二) 数据类型 Counter(计数器类型) Counter类型的指标的工作方式和计数器一样,只增不减(除非系统发生了重置),Counter一般用于累计值. Gauges(仪 ...

随机推荐

  1. Mark IntelliJ IDEA 2018.2.3破解

    来源:https://blog.csdn.net/qq_38060935/article/details/90377761

  2. Josephus问题(Ⅱ)

    题目描述 n个人排成一圈,按顺时针方向依次编号1,2,3-n.从编号为1的人开始顺时针"一二"报数,报到2的人退出圈子.这样不断循环下去,圈子里的人将不断减少.最终一定会剩下一个人 ...

  3. Hadoop中HDFS 的相关进程以及工作流程图(详细流程图)

  4. 浩若烟海事半功倍|利用Docker容器技术构建自动化分布式web测试集群Selenium Grid

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_195 "世界上有那么多城市,城市里有那么多的酒馆,可她,却偏偏走进了我的-",这是电影<卡萨布拉卡> ...

  5. odoo14 重启服务后权限不见了

    1 Odoo14权限更新有两个地方: 2 一.你在编写xml权限记录的时候没有将noupdate设置为'1'这样导致你每次升级模块,你的权限都会重置一遍. 3 二.你在运行odoo-bin服务的时候, ...

  6. 从零开始Blazor Server(8)--增加菜单以及调整位置

    这篇干啥 这篇文章主要是把前面的一些东西稍微调整一下,使其更适合后面的内容. 主要是两个事,一个是把原来的PermissionEntity直接变成MenuEntity,直接让最后一级是菜单,这样后面就 ...

  7. Auto.js 特殊定位控件方法 不能在ui线程执行阻塞操作,请使用setTimeout代替

    本文所有教程及源码.软件仅为技术研究.不涉及计算机信息系统功能的删除.修改.增加.干扰,更不会影响计算机信息系统的正常运行.不得将代码用于非法用途,如侵立删! Auto.js 特殊定位控件方法 操作环 ...

  8. Apache DolphinScheduler之最美好的遇见

    关于 Apache DolphinScheduler社区 Apache DolphinScheduler(incubator) 于17年在易观数科立项,19年3月开源, 19 年8月进入Apache ...

  9. Synchronized锁升级原理与过程深入剖析

    Synchronized锁升级原理与过程深入剖析 前言 在上篇文章深入学习Synchronized各种使用方法当中我们仔细介绍了在各种情况下该如何使用synchronized关键字.因为在我们写的程序 ...

  10. ShardingSphere-JDBC实战

    一.环境准备 1.数据库 创建2个库2个表: xdclass_shop_order_0 product_order_0 product_order_1 ad_config product_order_ ...