{{ $labels.instance }} is empty in rule execution

53 views
Skip to first unread message

Jhanssen Fávaro

unread,
Oct 21, 2020, 9:31:54 AM10/21/20
to Prometheus Users

Hi folks,
I am brand new in prometheus world, and I have an understanding/basic question:

Why from a rule file I can not retrieve the {{  $labels.instance }} variable ?

Sample Kafka Alert:
    - alert: Under_Replicated_Partition_Count
      expr: sum(kafka_server_replicamanager_underreplicatedpartitions) by(env) > 0
      for: 1m
      labels:
        severity: critical
        oid: "1.3.6.1.4.1.XXXX.15.1.2.3.1"
        instance: "{{ $labels.service_name }}"
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: {{ $value }} under replicated partitons'
        description: 'Under-replicated partitions means that one or more replicas are not available. This is usually because a broker is down.  Restart the broker, and check for errors in the logs.'


This bold line is same as anything... I've tried already in the annotation/description  section, also but no look..

Any ideas or how wold I managed to get this done ?


Best regards!
Jhanssen

Jhanssen Fávaro

unread,
Oct 21, 2020, 9:34:09 AM10/21/20
to Prometheus Users
Correction...
I meant:

        instance: "{{ $labels.instance}}"

Brian Brazil

unread,
Oct 21, 2020, 9:38:09 AM10/21/20
to Jhanssen Fávaro, Prometheus Users
On Wed, 21 Oct 2020 at 14:32, Jhanssen Fávaro <jhansse...@gmail.com> wrote:

Hi folks,
I am brand new in prometheus world, and I have an understanding/basic question:

Why from a rule file I can not retrieve the {{  $labels.instance }} variable ?

There is no instance label, as you aggregated it away with the sum(). If you want to have that label available you would mention it in the by clause, or use without and mention only the labels you wanted to remove.

Brian
 

Sample Kafka Alert:
    - alert: Under_Replicated_Partition_Count
      expr: sum(kafka_server_replicamanager_underreplicatedpartitions) by(env) > 0
      for: 1m
      labels:
        severity: critical
        oid: "1.3.6.1.4.1.XXXX.15.1.2.3.1"
        instance: "{{ $labels.service_name }}"
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: {{ $value }} under replicated partitons'
        description: 'Under-replicated partitions means that one or more replicas are not available. This is usually because a broker is down.  Restart the broker, and check for errors in the logs.'


This bold line is same as anything... I've tried already in the annotation/description  section, also but no look..

Any ideas or how wold I managed to get this done ?


Best regards!
Jhanssen

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/f4f864b8-671f-4568-8251-cef279e894ebn%40googlegroups.com.


--

Jhanssen Fávaro

unread,
Oct 21, 2020, 9:40:19 AM10/21/20
to Prometheus Users
Got it, thanks man. Already thought on this also, will try that.

Best Regards!
Reply all
Reply to author
Forward
0 new messages