Understand the config file

Viewed 102

Im running an exporter that fetch metrics from kafka. Im a newbie in Prometheus, so trying to understand(searching right documents) to know the meaning of the exporter config file.

Here is my config:

  #kafka.producer:type=producer-topic-metrics,client-id="{clientid}",topic="{topic}"", partition="{partition}"
  #kafka.consumer:type=consumer-fetch-manager-metrics,client-id="{clientid}",topic="{topic}"", partition="{partition}"
  - pattern: kafka.(.+)<type=(.+)-metrics, client-id=(.+), topic=(.+), partition=(.+)><>(.+-total|compression-rate|.+-avg|.+-replica|.+-lag|.+-lead)
    name: kafka_$2_$6
    labels:
      clientId: "$3"
      topic: "$4"
      partition: "$5"
    help: "Kafka $1 JMX metric type $2"
    type: GAUGE

Basically where the flag name reflect in the Prometheus also what is that $1, $2,$3 - where are they fetching the value)

2 Answers

The name flag will be the metric name. If your kafka and prometheus instance are running, you can see the list of metrics in prometheus (it's in localhost:9090/graph for me).

As for the $1, it's the regex capturing group, so it's everything that's between brackets. You can see that the clientId is $3, which is the thirst capturing group.

Looks like you are defining a recording rule in Prometheus. This rule creates a new metric with the name: kafka_$2_$6 and labels with respective values for each: clientId: "$3", topic: "$4", partition: "$5". The values are extracted from the pattern attribute.

I tried to paste your regex on an editor and it is not fully working. I can get until parameter $5 but not the $6. Basically, you have the pattern

kafka.(.+)<type=(.+)-metrics,client-id=(.+),topic=(.+),partition=(.+)

and if you have the string :

kafka.producer<type=producer-topic-metrics,client-id=clientid,topic=topic_name,partition=partition_name

you can extract these values from it:

group 1: 6-14   producer
group 2: 20-34  producer-topic
group 3: 53-63  clientid
group 4: 70-82  topic_name
group 5: 93-109 partition_name

then it will be used on the following labels. For instance, the name of your metric is defined in name: kafka_$2_$6 and it will become name: kafka_producer-topic_{wharever_is_in_6}. Check here the interactive editor.

Related