I am trying to solve a problem of making a sum and group by query in Prometheus on a metric where the labels assigned to the metric values to unique to my sum and group by requirements.
I have a metric sampling sizes of ElasticSearch indices, where the index names are labelled on the metric. The indices are named like this and are placed in the label "index":
project.<projectname>.<uniqueid>.<date>
with concrete value that would look like this:
project.sample-x.ad19f880-2f16-11e7-8a64-jkzdfaskdfjk.2018.03.12
project.sample-y.jkcjdjdk-1234-11e7-kdjd-005056bf2fbf.2018.03.12
project.sample-x.ueruwuhd-dsfg-11e7-8a64-kdfjkjdjdjkk.2018.03.11
project.sample-y.jksdjkfs-2f16-11e7-3454-005056bf2fbf.2018.03.11
so if I had the short version of values in the "index" label I would just do:
sum(metric) by (index)
but what I am trying to do is something like this:
sum(metric) by ("project.<projectname>")
where I can group by a substring of the "index" label. How can this be done with a Prometheus query? I assume this could maybe be solved using a label_replace as part of the group, but I can't just see how to "truncate" the label value to achieve this.
Best regards
Lars Milland