Our service receives both front-office(website) and back office calls. I want to separate these calls in my metrics in my grafana boards.
We know certain urls and methods combinations are only used by back office, like "PUT /page/draft" and "POST /page/publish". But there are several endpoints also used by front-office, like "GET /page/draft". So the query should combine two tags, like
http_server_requests({uri="/page/draft", method="PUT"}) OR ...
How can I use a variable of type query(or anything else) to filter them, so that in my graphs I can use http_server_requests({"$backoffice_requests"})
and http_server_requests({"$non_backoffice_requests"})
to draw two graphs?
So from what I see you have two options (maybe there are better ones out there but I can't think of any) IF doing the labeling directly in the instrumented service(s) is not an option.
Modifying the Prometheus config to add a label that identifies environments like "front" and "back" based on the values of other labels OR doing it at "query time" with Grafana template variables and PromQL. Both come with up- and downsides.
Option 1: Adding a label at scrape time
Advantages:
label_replace
or regex selectors overall nor using stuff specific to Grafana.Disadvantages:
(a|b|c)
statement.How to do:
Add a
metric_relabel_config
(see here) to the respective job(s) in the Prometheus config. The basic idea is that you can regex match labels and add a new label with a specific value if a match occurs.Here is an example:
What this does is first adding the label
scope
with the default valueunknown
to all series and than continues to change the label based on the value of other labels.Option 2: Separating at runtime in Grafana
tba