Search code examples
prometheuspromqlprometheus-alertmanager

PromQL : compare metric value with its label's value


I have this metric : my_metric{expected_value="123"} 123

Using Prometheus, how can create an alert that triggers when the value differs from the label expected_value's value ?


Solution

  • You cannot. Labels are not supposed to be used in this way, and there are no ways of combination labels and metric values.

    Best course of action in this case would be to split your metric into two metrics:

    my_metric 123
    my_metric_expected_value 123
    

    And introduce alerting rule based on expression:

    my_metric != my_metric_expected_value