10

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
  },
funtoos
  • 295
  • 1
  • 4
  • 17

3 Answers3

8

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)

valyala
  • 11,669
  • 1
  • 59
  • 62
  • can you please show me how the json out would like ? I have edited the question with a output – funtoos Jan 10 '20 at 19:27
  • Just put the string in `query`. Something like the following: `"query": "label_values({__name__=~\"application_.*Count_total\"}, xyx)"` – valyala Jan 10 '20 at 20:06
  • Gettting error Template variables could not be initialized: parse error at char 12: unexpected character inside braces: '\\' – funtoos Jan 10 '20 at 21:04
  • 1
    Note the `.` is very important. Was doing `...=~"search term*"` and didn't work. Just need to make sure it was `.*`. Example: `{job_name=~"watcher-job-.*"}` – mwilson Oct 14 '22 at 03:04
3

@valyala, I got it working with

"query": "metrics(application_get.*Count_total)",
"regex": "/application_get(.*)Count_total/",

funtoos
  • 295
  • 1
  • 4
  • 17
3

In my Promql, this worked for me:

topk(5, {__name__=~"thing_you_want_to_search.*"})

which finds the first 5 lines that matches the thing_you_want_to_search*

A H
  • 2,164
  • 1
  • 21
  • 36