Prometheus-Grafana : How to use wildcard in query

funtoos picture funtoos · Jan 10, 2020 · Viewed 11.7k times · Source

I have below labels in prometheus, how to create wildcard query while templating something like “query”: “label_values(application_*Count_Total,xyx)” . These values are generated from a Eclipse Microprofile REST-API

application_getEnvVariablesCount_total
application_getFEPmemberCount_total
application_getLOBDetailsCount_total
application_getPropertiesCount_total
  {
    "allValue": null,
    "current": {
      "isNone": true,
      "selected": false,
      "text": "None",
      "value": ""
    },
    "datasource": "bcnc-prometheus",
    "definition": "microprofile1",
    "hide": 0,
    "includeAll": false,
    "label": null,
    "multi": false,
    "name": "newtest",
    "options": [
      {
        "isNone": true,
        "selected": true,
        "text": "None",
        "value": ""
      }
    ],
    "query": "microprofile1",
    "refresh": 0,
    "regex": "{__name__=~\"application_.*Count_total\"}",
    "skipUrlSync": false,
    "sort": 0,
    "tagValuesQuery": "",
    "tags": [],
    "tagsQuery": "",
    "type": "query",
    "useTags": false
  },

Answer

valyala picture valyala · Jan 10, 2020

Prometheus treats metric names the same way as label values with a special label - __name__. So the following query should select all the values for label xyx across metrics with names matching application_.*Count_total regexp:

label_values({__name__=~"application_.*Count_total"}, xyx)