---
apiVersion: v1
kind: ConfigMap
metadata:
  name: kafka-metrics
  labels:
    app: kafka
data:
  jmx-kafka-prometheus.yml: |+
    jmxUrl: service:jmx:rmi:///jndi/rmi://127.0.0.1:5555/jmxrmi
    lowercaseOutputName: true
    lowercaseOutputLabelNames: true
    ssl: false

    whitelistObjectNames: ["kafka.controller:*","kafka.server:*","java.lang:*","kafka.network:*","kafka.log:*"]

    rules:
    - pattern: kafka.controller<type=(ControllerChannelManager), name=(QueueSize), broker-id=(\d+)><>(Value)
      name: kafka_controller_$1_$2_$4
      labels:
        broker_id: "$3"
    - pattern: kafka.controller<type=(ControllerChannelManager), name=(TotalQueueSize)><>(Value)
      name: kafka_controller_$1_$2_$3
    - pattern: kafka.controller<type=(KafkaController), name=(.+)><>(Value)
      name: kafka_controller_$1_$2_$3
    - pattern: kafka.controller<type=(ControllerStats), name=(.+)><>(Count)
      name: kafka_controller_$1_$2_$3
    - pattern: kafka.server<type=(ReplicaFetcherManager), name=(.+), clientId=(.+)><>(Value)
      name: kafka_server_$1_$2_$4
      labels:
        client_id: "$3"
    - pattern : kafka.network<type=(Processor), name=(IdlePercent), networkProcessor=(.+)><>(Value)
      name: kafka_network_$1_$2_$4
      labels:
        network_processor: $3
    - pattern : kafka.network<type=(RequestMetrics), name=(RequestsPerSec), request=(.+)><>(Count)
      name: kafka_network_$1_$2_$4
      labels:
        request: $3
    - pattern: kafka.server<type=(.+), name=(.+), topic=(.+)><>(Count|OneMinuteRate)
      name: kafka_server_$1_$2_$4
      labels:
        topic: $3
    - pattern: kafka.server<type=(DelayedOperationPurgatory), name=(.+), delayedOperation=(.+)><>(Value)
      name: kafka_server_$1_$2_$3_$4
    - pattern: kafka.server<type=(.+), name=(.+)><>(Count|Value|OneMinuteRate)
      name: kafka_server_$1_total_$2_$3
    - pattern: kafka.server<type=(.+)><>(queue-size)
      name: kafka_server_$1_$2
    - pattern: java.lang<type=(.+), name=(.+)><(.+)>(\w+)
      name: java_lang_$1_$4_$3_$2
    - pattern: java.lang<type=(.+), name=(.+)><>(\w+)
      name: java_lang_$1_$3_$2
    - pattern : java.lang<type=(.*)>
    - pattern: kafka.log<type=(.+), name=(.+), topic=(.+), partition=(.+)><>Value
      name: kafka_log_$1_$2
      labels:
        topic: $3
        partition: $4
