2
votes

Im wondering if I can use "Info" (https://github.com/prometheus/client_python#info) metric from prometheus data to display info/data in grafana. I haven't found any meaningful examples online with regards to using that metric. I've checked the sample dashboards but I don't see any use of that metric. I've tried sending data to prometheus with the example in the link above:

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)

Anyone have meaningful queries/visual in grafana that I can use? Im trying to see if I can display this as a table some how.

2
The answer to this question may be what you are looking for stackoverflow.com/questions/58627208/…Michael Doubez

2 Answers

3
votes

I have a build_info metric exported by all services that looks like this:

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

And an availability graph on the service dashboard that shows how many instances are running as a filled area (plus lines for how many are supposed to be running, count(up{job="$job",env="$env"}), and the alerting thresholds; the dashboard defines $job and $env template variables) that looks like this:

Availability graph

So I'm using the version label (and when that's not available, e.g. for test deployments, the Git commit_id) as a label for the running instances count.

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", "$1", "build", "MASTER_(.{7}).+"),# Retain the `commit_id` if `version == "MASTER"
"build", "$1", "build", "(.+)_.+")         # Else, retain `version`

To end up with a metric that looks like:

{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

And finally, in the query legend format in Grafana I put Version {{ build }}, to end up with Version 19.57.3 in the legend.

On the graph you will notice for example that we went from 19.57.2 to 19.58.3, but then had to roll back to 19.57.3 last evening due to a regression.

Edit Here's the JSON for a table panel that shows pretty much what you want. (It is based on editing in place the https://play.grafana.org/d/000000065/prometheus-console-tables?orgId=1 dashboard you provided.)

{
"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": {}
}
1
votes

I realized that looking into pushgateway the info metric is a gauge that has value of 1. I suppose I can use gauge as a way to build the table with the metrics.