my application emits counter metrics something like this:
app_counters_some_client_response_code_201_count_value{}
app_counters_some_client_response_code_400_count_value{}
app_counters_some_client_response_code_404_count_value{}
I want to create a graphana dashboard which can show all these different metric values in the same dashboard with the status codes as the legend.. how can I write such a single query using a wildcard as there can be multiple response codes and we don't have the complete list of possible values, so we won't be able to write a different query for each metric
First of all, such metrics are a bad idea for exactly the problem you are having. Please read recommendations on exposing metrics, and consider changing your metrics to use labels. Something like
That being said, you could use a query:
and specify legend in the Grafana panel as
{{http_code}}
Explanation:
This query:
{__name__=~"app_counters_some_client_response_code_\d+_count_value"}
gets all time series with name matching regexapp_counters_some_client_response_code_\d+_count_value
label_replace
extracts digits from the names of the metrics and puts them into the labelhttp_code
.