Grafana Prometheus "Info" 指标

Grafana Prometheus "Info" Metric

我想知道我是否可以使用普罗米修斯数据中的 "Info" (https://github.com/prometheus/client_python#info) 指标在 grafana 中显示 info/data。关于使用该指标,我还没有在网上找到任何有意义的例子。我已经检查了示例仪表板,但没有看到该指标的任何用途。我已经尝试使用上面 link 中的示例将数据发送到普罗米修斯:

from prometheus_client import Info, push_to_gateway, CollectorRegistry
regis = CollectorRegistry()
i = Info('my_build_version', 'Description of info')
i.info({'version': '1.2.3', 'buildhost': 'foo@bar'})
push_to_gateway('http://localhost:9091', job="Try_Info_metric", registry=regis)

有人在我可以使用的 grafana 中提供有意义的 queries/visual 吗?我想看看我是否可以将其显示为 table 某种方式。

我意识到查看 pushgateway 信息指标是一个值为 1 的指标。 我想我可以使用 gauge 来构建 table 和指标。

我有一个由所有服务导出的 build_info 指标,如下所示:

build_info{commit_id="42806c2f7f1e17a63d94db9d561d220f53d38ee0",commit_time="2019-11-16 13:53:46Z",build_time="2019-11-16 13:57:20Z",branch="v19.57.x",version="19.57.3",} 1.0

服务仪表板上的可用性图表显示有多少实例 运行 作为填充区域(加上表示应该有多少实例的行 运行、count(up{job="$job",env="$env"})、和警报阈值;仪表板定义 $job$env 模板变量),如下所示:

所以我使用 version 标签(当它不可用时,例如对于测试部署,Git commit_id)作为 运行 实例计数。

label_replace(
label_replace(
label_join(
  sum without(instance) (
    build_info{job="$job",env="$env"}      # Take labels of `build_info`
      * on(job, env, instance) group_left  # Multiplied by `up`, for the actual value
    up{job="$job",env="$env"}),
  "build", "_", "version", "commit_id"),   # Join `version` and `commit_id` label values into label `build`
"build", "", "build", "MASTER_(.{7}).+"),# Retain the `commit_id` if `version == "MASTER"
"build", "", "build", "(.+)_.+")         # Else, retain `version`

最终得到一个如下所示的指标:

{branch="v19.57.x",build="19.57.3",build_time="2019-11-16 14:02:38Z",commit_id="42806c2f7f1e17a63d94db9d561d220f53d38ee0",commit_time="2019-11-16 13:53:46Z",env="prod",job="foo-service",version="19.57.3"} 10

最后,在 Grafana 的查询图例格式中,我输入 Version {{ build }},以图例中的 Version 19.57.3 结尾。

在图表上,您会注意到例如我们从 19.57.2 到 19.58.3,但由于回归,昨晚不得不回滚到 19.57.3。

编辑 这是 JSON 的 table 面板,几乎可以显示您想要的内容。 (它基于就地编辑您提供的 https://play.grafana.org/d/000000065/prometheus-console-tables?orgId=1 仪表板。)

{
"datasource": "demo.robustperception.io",
"columns": [
  {
    "text": "Current",
    "value": "current"
  }
],
"editable": true,
"error": false,
"fontSize": "100%",
"gridPos": {
  "h": 7,
  "w": 24,
  "x": 0,
  "y": 7
},
"id": 2,
"isNew": true,
"links": [],
"pageSize": null,
"scroll": true,
"showHeader": true,
"sort": {
  "col": 0,
  "desc": true
},
"styles": [
  {
    "dateFormat": "YYYY-MM-DD HH:mm:ss",
    "pattern": "Time",
    "type": "date"
  },
  {
    "alias": "up",
    "colorMode": null,
    "colors": [
      "rgba(245, 54, 54, 0.9)",
      "rgba(237, 129, 40, 0.89)",
      "rgba(50, 172, 45, 0.97)"
    ],
    "dateFormat": "YYYY-MM-DD HH:mm:ss",
    "decimals": 2,
    "pattern": "Value",
    "thresholds": [],
    "type": "number",
    "unit": "short"
  }
],
"targets": [
  {
    "expr": "sum by (job, instance, version, revision) ({__name__=~\".*_build_info\"})",
    "format": "table",
    "instant": true,
    "intervalFactor": 1,
    "refId": "A",
    "step": 30,
    "target": "",
    "hide": false,
    "legendFormat": ""
  }
],
"title": "Multiple queries merge",
"transform": "table",
"type": "table",
"options": {}
}