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. 在eclipse配置javafx

    JAVA学习中,遇到了这个问题,解决方法记录一下(我用的jdk11) 最新几版的eclipse中没有javafx,需要自己进行手动配置,先下载一下javafx的包,解压,找到lib文件夹(主要用的是这 ...

  2. 开源轻量级工作流WorkflowCore介绍

    在.Net Framework环境下,我们使用Windows Workflow Foundation(WF)作为项目的工作流引擎,可是.Net Core已经不支持WF了,需要为基于.Net Core的 ...

  3. python 参数类型理解

    简介 大家都知道,在java中,函数或者方法的参数在调用时必须对其进行传参操作,也就是所谓的必选参数,也可以称为位置参数,除此之外,python还拥有其他语言不具有的一些参数类型,以下将进行一一介绍. ...

  4. inotify 目录文件变更实时监控

    # inotify 软件 # 安装:通过epel,安装在客户端 # 功能:实时监控目录下文件的更变 # 监控事件:创建.删除.修改.移动... # 安装位置:客户端 # 安装命令: sudo apt- ...

  5. Kubernetes的整体架构

    K8s将集群中的机器划分为一个主节点和一群工作节点,在主节点上运行着集群管理相关的一组进程kube-apiserver.kube-controller-manager 和 kube-scheduler ...

  6. 解析MySQL存储过程的游标执行过程

    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 内容提纲 一.测试环境搭建 二.执行过程解析 三.注意事项 一.测试环境搭建 首先创建一张表,并插入几行数据字段: CRE ...

  7. 海豚调度直播来了 - 即将发版的1.3.0新特性及Roadmap路线

    在过去的3个多月,Apache DolphinScheduler(incuating)和DolphinScheduler社区发生了很多变化,今晚19:30在线直播将为大家介绍最新1.3.0的新特性及R ...

  8. Luogu3802 小魔女帕琪 (排列组合)

    注意除数为0情况 #include <iostream> #include <cstdio> #include <cstring> #include <alg ...

  9. Word 常识备忘录

    一句科普 名词解释 左右页边距 正文到纸左右两边之间的间距. 分页符 分页符是分页的一种符号,上一页结束以及下一页开始的位置. 分栏符 分栏的页面使用分栏符可以使一列分栏的段落排列到另一栏. 邮件合并 ...

  10. df空间满,du找不到文件的问题

    最近看了一下问题: df -h Filesystem Size Used Avail Use% Mounted on rootfs 271G 267G 2.2G 100% / 根分区满了,du 找不到 ...