Search code examples
prometheuspromqlprometheus-alertmanager

In PromQL is that possible to apply a filter on a whole expression and not only to metrics?


I have this expression that calculate in how many seconds my NAS will be full based on the evolution of the rate over 1 week.

((nas_storage_allocated_bytes - nas_storage_usage_bytes) / deriv(nas_storage_usage_bytes[1w]))

What I would like to do is to apply a filter to this whole expression, I would like to filter my NAS over a project, so the filter should be like that : {project="foo"}.

The solution I found is that I have to apply the filter to all the metrics in the expression like that :

((nas_storage_allocated_bytes{project="foo"} - nas_storage_usage_bytes{project="foo"}) / deriv(nas_storage_usage_bytes{project="foo"}[1w]))

My question is simple, is that possible to have one filter to apply to the whole expression and not have to repeat it for each metrics present in the expression ?


Solution

  • You can apply the filter just to the first metric (or to other one) instead of applying it to all metrics as you did. It's not exactly what you want but it simplifies the PromQL.

    ((nas_storage_allocated_bytes{project="foo"} - nas_storage_usage_bytes) / deriv(nas_storage_usage_bytes[1w]))