go - PromQL 查询来绘制传入请求的速率

标签 go prometheus promql

我是普罗米修斯的新手。我正在使用 NewCounterVec 记录传入的 http 请求。我根据在 git hub 上找到的许多其他人的代码使用了它。

假设我的指标是这样定义的(在 go 中)

httpRequests = prometheus.NewCounterVec(
    prometheus.CounterOpts{
        Name: "http_requests_total",
        Help: "Incoming http requests.",
    },
    []string{"path", "status"},
)

path 传入的 url 路径和 status 是 http 响应状态。 我的 promQL 查询(绘制图表)是什么

  1. 每分钟传入请求数
  2. 基于 HTTP 状态的失败率 代码(状态码 >=400)

我试过 rate(http_requests_total[5m])[30m:1m] 基于 this ,但这不能在图表上显示。它抛出错误 Error executing query: invalid expression type "range vector"for range query, must be Scalar or instant Vector

最佳答案

Incoming requests per minute

速率(http_requests_total[5m]) * 60

Rate of failure based on http status code (status code >=400)

rate(http_requests_total{status=~"[45].."}[5m])

然而,这是脆弱的,如果没有 4xx 或 5xx 状态代码,则不会返回任何内容。

关于go - PromQL 查询来绘制传入请求的速率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60272642/

相关文章:

json - 如何使用 Go 将对象数组插入 MongoDB

json - Golang JSON RawMessage 文字

Prometheusmetrics_path 被编码

Docker prom/Prometheus 容器退出

prometheus - 如何将客户端应用程序事件导入普罗米修斯

timestamp - 带有时间戳的普罗米修斯指标

适用于所有平台的二进制文件

go - 在测试Buffalo应用程序期间禁用信息日志

grafana - 如何使用 Prometheus 和collectd 导出器绘制grafana 中的CPU 使用情况图?

prometheus - 设置 PromQL 值的格式