nginx - Prometheus 直方图度量不准确
问题描述
我们将 Nginx 日志由 Logstash 处理到 ES 中。我们可以从该数据中填充响应时间图。但是我们只能在有限的时间内保留日志。因此,普罗米修斯。使用 logstash-output-prometheus 插件,我将request_time
值作为直方图指标发送。
prometheus {
timer => {
http_request_duration_seconds => {
description => "HTTP request_time from Nginx logs"
value => "%{[request_time]}"
type => "histogram"
buckets => [ 0.005, 0.01, 0.025, 0.05, 0.1, 0.2, 0.3, 04, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.5, 2, 3, 4, 5, 10, 60, 120, 300, 600 ]
labels => {
api => "%{api}"
method => "%{method}"
status => "%{status_agg}"
path => "%{uri_name}"
host => "%{host}"
}
}
}
}
当我比较 Logstash 与 Prometheus 的第 95 个百分位值时,它们有时非常不同。
在上图中,底部图表由 Logstash ES 填充。2 台主机的值约为 10 毫秒,其余 4 台主机的值约为 11 毫秒。
(ES查询type:"nginx" AND host:"prod-lb" AND uri_name:"/api/status" AND method:"GET" AND status:"200"
:)
Prometheus 显示 2 个主机的值约为 10 毫秒(✅),但其余 4 个主机的显示值约为 18 毫秒!
(普罗米修斯查询histogram_quantile(0.95, sum by(le, path, host, method, status) (rate(http_request_duration_seconds_bucket{path="/api/status", host=~".*lb.*"}[2m])))
:)
(请注意,这些值周围的桶是 5ms、10ms、25ms)
这种巨大的偏差是预期的吗?
我怎样才能使它更准确?
还有其他方法可以保持更准确的响应时间吗?
解决方案
推荐阅读
- google-sheets - 堆叠和分组条形图
- angular - 术语可重用组件在 angular/react/vue 中是什么意思?
- reactjs - 如何在 React 前端集成/使用 yFiles for Html BPMN 编辑器来编辑 bpmn 图?
- spring-boot - Spring boot App - 无法在项目上执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile
- javascript - if 函数中的许多条件在 JavaScript 中不起作用
- c - C pthread 不启动
- java - 是否有 ScheduledFuture 的实现?
- python-3.x - PyGObject:如何检测 Gio.DataInputStream 的结束?
- unity3d - 如何让 Vuforia 和 MRTK MultiScene 系统正常工作?
- php - 问题在 Windows 上的 XAMPP 上设置两个 PHP 版本