prometheus / jmx_exporter

A process for exposing JMX Beans via HTTP for Prometheus consumption
Apache License 2.0
3.06k stars 1.2k forks source link

Add example config file for kafka kraft mode metrics #906

Closed KumKeeHyun closed 10 months ago

KumKeeHyun commented 10 months ago

@dhoard

After looking issue #881 and pr #793, i created this pr.

The kraft-related metrics are raft-metrics, raft-channel-metrics, and broker-metadata-metrics, and the reason why these metrics could not be collected with the kafka-2_0_0.yml rules is that the name was set to attrName.

jconsole-raft-metrics

I added the following rules based on kafka-2_0_0.yml file for these metrics.

# Kraft current state info metric rule
- pattern: "kafka.server<type=raft-metrics><>current-state: ([a-z]+)"
  name: kafka_server_raft_metrics_current_state_info
  type: GAUGE
  value: 1
  labels:
    "state": "$1"
# Kraft specific rules for raft-metrics, raft-channel-metrics, broker-metadata-metrics
- pattern: kafka.server<type=(.+)><>([a-z-]+)-total
  name: kafka_server_$1_$2_total
  type: COUNTER
- pattern: kafka.server<type=(.+)><>([a-z-]+)
  name: kafka_server_$1_$2
  type: GAUGE

And we also get these:

# HELP kafka_server_raft_metrics_current_state_info The current state of this member; possible values are leader, candidate, voted, follower, unattached, observer kafka.server:name=null,type=raft-metrics,attribute=current-state
# TYPE kafka_server_raft_metrics_current_state_info gauge
kafka_server_raft_metrics_current_state_info{state="follower",} 1.0
# HELP kafka_server_raft_metrics_log_end_epoch The current raft log end epoch. kafka.server:name=null,type=raft-metrics,attribute=log-end-epoch
# TYPE kafka_server_raft_metrics_log_end_epoch gauge
kafka_server_raft_metrics_log_end_epoch 134.0
...
# HELP kafka_server_raft_channel_metrics_request_total The total number of requests sent kafka.server:name=null,type=raft-channel-metrics,attribute=request-total
# TYPE kafka_server_raft_channel_metrics_request_total counter
kafka_server_raft_channel_metrics_request_total 693158.0
# HELP kafka_server_raft_channel_metrics_response_total The total number of responses received kafka.server:name=null,type=raft-channel-metrics,attribute=response-total
# TYPE kafka_server_raft_channel_metrics_response_total counter
kafka_server_raft_channel_metrics_response_total 693148.0
...
dhoard commented 10 months ago

@KumKeeHyun Thanks for the PR! I'll merge the code.