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