Prometheus-Grafana : How to use wildcard in query
Asked Answered
D

3

14

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
  },
Dismount answered 10/1, 2020 at 15:4 Comment(0)
W
12

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)

Willodeanwilloughby answered 10/1, 2020 at 16:40 Comment(4)
can you please show me how the json out would like ? I have edited the question with a outputDismount
Just put the string in query. Something like the following: "query": "label_values({__name__=~\"application_.*Count_total\"}, xyx)"Willodeanwilloughby
Gettting error Template variables could not be initialized: parse error at char 12: unexpected character inside braces: '\\'Dismount
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-.*"}Coniine
D
4

@valyala, I got it working with

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

Dismount answered 11/1, 2020 at 2:46 Comment(0)
S
4

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*

Slicer answered 31/3, 2022 at 1:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.