apiVersion: v1
kind: ConfigMap
metadata:
  name: kafka-metrics
  labels:
    app.kubernetes.io/managed-by: kas-fleetshard-operator
data:
  jmx-exporter-config: |
    lowercaseOutputName: true
    #
    # Note that whitespace is important in the rule pattern - there
    # needs to be a space after each comma.
    #
    # Bad: 'kafka.server<type=(.+),listener=(.+),networkProcessor=(.+)><>(.+):'
    # Good: 'kafka.server<type=(.+), listener=(.+), networkProcessor=(.+)><>(.+):'
    #
    rules:
      - labels:
          clientID: $3
          partition: $5
          topic: $4
        name: kafka_server_$1_$2
        pattern: >-
          kafka.server<type=(.+), name=(.+), clientId=(.+), topic=(.+),
          partition=(.*)><>Value
        type: GAUGE
      - labels:
          broker: '$4:$5'
          clientId: $3
        name: kafka_server_$1_$2
        pattern: >-
          kafka.server<type=(.+), name=(.+), clientId=(.+), brokerHost=(.+),
          brokerPort=(.+)><>Value
        type: GAUGE
      - labels:
          cipher: $5
          listener: $2
          networkProcessor: $3
          protocol: $4
        name: kafka_server_$1_connections_tls_info
        pattern: >-
          kafka.server<type=(.+), cipher=(.+), protocol=(.+), listener=(.+),
          networkProcessor=(.+)><>connections
        type: GAUGE
      - labels:
          clientSoftwareName: $2
          clientSoftwareVersion: $3
          listener: $4
          networkProcessor: $5
        name: kafka_server_$1_connections_software
        pattern: >-
          kafka.server<type=(.+), clientSoftwareName=(.+),
          clientSoftwareVersion=(.+), listener=(.+),
          networkProcessor=(.+)><>connections
        type: GAUGE
      - labels:
          listener: $2
          networkProcessor: $3
        name: kafka_server_$1_$4
        pattern: 'kafka.server<type=(.+), listener=(.+), networkProcessor=(.+)><>(.+):'
        type: GAUGE
      - labels:
          listener: $2
          networkProcessor: $3
        name: kafka_server_$1_$4
        pattern: 'kafka.server<type=(.+), listener=(.+), networkProcessor=(.+)><>(.+)'
        type: GAUGE
      - labels:
          clientId: $3
          brokerHost: $4
          brokerPort: $5
        name: kafka_server_$1_$2
        pattern: 'kafka.server<type=(.+), name=(.+), clientId=(.+), brokerHost=(.+), brokerPort=(.+)><>(.+)'
        type: GAUGE
      - labels:
          clientId: $3
        name: kafka_server_$1_$2
        pattern: 'kafka.server<type=(.+), name=(.+), clientId=(.+)><>(.+)'
        type: GAUGE
      - name: kafka_controller_kafkacontroller_offline_partitions_count
        pattern: >-
          kafka.controller<type=KafkaController,
          name=OfflinePartitionsCount><>Value
        type: GAUGE
      - name: kafka_server_replicamanager_under_replicated_partitions
        pattern: >-
          kafka.server<type=ReplicaManager,
          name=UnderReplicatedPartitions><>Value
        type: GAUGE
      - name: kafka_server_replicamanager_at_min_isr_partition_count
        pattern: >-
          kafka.server<type=ReplicaManager,
          name=AtMinIsrPartitionCount><>Value
        type: GAUGE
      - labels:
          partition: $2
          topic: $1
        name: kafka_cluster_partition_at_min_isr
        pattern: >-
          kafka.cluster<type=Partition, name=AtMinIsr, topic=(.+),
          partition=(.*)><>Value
        type: GAUGE
      - name: kafka_server_replicamanager_under_min_isr_partition_count
        pattern: >-
          kafka.server<type=ReplicaManager,
          name=UnderMinIsrPartitionCount><>Value
        type: GAUGE
      - labels:
          partition: $2
          topic: $1
        name: kafka_cluster_partition_under_min_isr
        pattern: >-
          kafka.cluster<type=Partition, name=UnderMinIsr, topic=(.+),
          partition=(.*)><>Value
        type: GAUGE
      - name: kafka_controller_kafkacontroller_active_controller_count
        pattern: >-
          kafka.controller<type=KafkaController,
          name=ActiveControllerCount><>Value
        type: GAUGE
      - name: kafka_server_replicamanager_leader_count
        pattern: 'kafka.server<type=ReplicaManager, name=LeaderCount><>Value'
        type: GAUGE
      - labels:
          topic: $1
        name: kafka_server_brokertopicmetrics_bytes_in_total
        pattern: >-
          kafka.server<type=BrokerTopicMetrics, name=BytesInPerSec,
          topic=(.+)><>Count
        type: GAUGE
      - labels:
          topic: $1
        name: kafka_server_brokertopicmetrics_bytes_out_total
        pattern: >-
          kafka.server<type=BrokerTopicMetrics, name=BytesOutPerSec,
          topic=(.+)><>Count
        type: GAUGE
      - labels:
          topic: $1
        name: kafka_server_brokertopicmetrics_messages_in_total
        pattern: >-
          kafka.server<type=BrokerTopicMetrics, name=MessagesInPerSec,
          topic=(.+)><>Count
        type: GAUGE
      - name: kafka_controller_kafkacontroller_global_partition_count
        pattern: >-
          kafka.controller<type=KafkaController,
          name=GlobalPartitionCount><>Value
        type: GAUGE
      - labels:
          partition: $2
          topic: $1
        name: kafka_log_log_size
        pattern: 'kafka.log<type=Log, name=Size, topic=(.+), partition=(.*)><>Value'
        type: GAUGE
      - name: kafka_log_logmanager_offline_log_directory_count
        pattern: 'kafka.log<type=LogManager, name=OfflineLogDirectoryCount><>Value'
        type: GAUGE
      - name: kafka_controller_controllerstats_unclean_leader_elections_total
        pattern: >-
          kafka.controller<type=ControllerStats,
          name=UncleanLeaderElectionsPerSec><>Count
        type: GAUGE
      - name: kafka_server_replicamanager_partition_count
        pattern: 'kafka.server<type=ReplicaManager, name=PartitionCount><>Value'
        type: GAUGE
      - labels:
          topic: $1
        name: kafka_server_brokertopicmetrics_total_produce_requests_total
        pattern: >-
          kafka.server<type=BrokerTopicMetrics,
          name=TotalProduceRequestsPerSec, topic=(.+)><>Count
        type: COUNTER
      - name: kafka_server_brokertopicmetrics_failed_produce_requests_total
        pattern: >-
          kafka.server<type=BrokerTopicMetrics,
          name=FailedProduceRequestsPerSec><>Count
        type: COUNTER
      - labels:
          topic: $1
        name: kafka_server_brokertopicmetrics_total_fetch_requests_total
        pattern: >-
          kafka.server<type=BrokerTopicMetrics, name=TotalFetchRequestsPerSec,
          topic=(.+)><>Count
        type: COUNTER
      - name: kafka_server_brokertopicmetrics_failed_fetch_requests_total
        pattern: >-
          kafka.server<type=BrokerTopicMetrics,
          name=FailedFetchRequestsPerSec><>Count
        type: COUNTER
      - name: kafka_network_socketserver_network_processor_avg_idle_percent
        pattern: >-
          kafka.network<type=SocketServer,
          name=NetworkProcessorAvgIdlePercent><>Value
        type: GAUGE
      - name: >-
          kafka_server_kafkarequesthandlerpool_request_handler_avg_idle_percent
        pattern: >-
          kafka.server<type=KafkaRequestHandlerPool,
          name=RequestHandlerAvgIdlePercent><>MeanRate
        type: GAUGE
      - labels:
          partition: $2
          topic: $1
        name: kafka_cluster_partition_replicas_count
        pattern: >-
          kafka.cluster<type=Partition, name=ReplicasCount, topic=(.+),
          partition=(.*)><>Value
        type: GAUGE
      - labels:
          $1: $2
          quantile: 0.$3
        name: kafka_network_requestmetrics_total_time_ms
        pattern: >-
          kafka.network<type=RequestMetrics, name=TotalTimeMs,
          (.+)=(.+)><>(\d+)thPercentile
        type: GAUGE
      - pattern: kafka.server<type=socket-server-metrics, listener=(.+), networkProcessor=(.+)><>connection-count
        name: kafka_server_socket_listener_connection_count
        type: GAUGE
        labels:
          listener: "$1"
          networkProcessor: "$2"
      - pattern: kafka.server<type=socket-server-metrics, listener=(.+), networkProcessor=(.+)><>connection-creation-rate
        name: kafka_server_socket_listener_connection_creation_rate
        type: GAUGE
        labels:
          listener: "$1"
          networkProcessor: "$2"
      - pattern: kafka.network<type=RequestMetrics, name=ErrorsPerSec, request=(.+), error=(.+)><>Count
        name: kafka_network_request_errors_total
        type: COUNTER
        labels:
          request: "$1"
          error: "$2"
      - pattern: kafka.server<type=socket-server-metrics><>broker-connection-accept-rate
        name: kafka_server_socket_broker_connection_accept_rate
        type: GAUGE
      - pattern: kafka.server<type=socket-server-metrics, listener=(.+)><>connection-accept-throttle-time
        name: kafka_server_socket_listener_connection_accept_throttle_time
        type: GAUGE
        labels:
          listener: "$1"
      - pattern: kafka.server<type=Produce, quota.type=PRODUCE><>byte-rate
        name: kafka_server_produce_byte_rate
        type: GAUGE
      - pattern: kafka.server<type=Produce, quota.type=PRODUCE><>throttle-time
        name: kafka_server_produce_throttle_time
        type: GAUGE
      - pattern: kafka.server<type=Fetch, quota.type=FETCH><>byte-rate
        name: kafka_server_fetch_byte_rate
        type: GAUGE
      - pattern: kafka.server<type=Fetch, quota.type=FETCH><>throttle-time
        name: kafka_server_fetch_throttle_time
        type: GAUGE
      - pattern: kafka.server<type=Request, quota.type=REQUEST><>request-rate
        name: kafka_server_request_request_rate
        type: GAUGE
      - pattern: kafka.server<type=Request, quota.type=REQUEST><>throttle-time
        name: kafka_server_request_throttle_time
        type: GAUGE
      - pattern : io.strimzi.kafka.quotas<type=StorageChecker, name=(.+)><>Value
        name: kafka_broker_quota_$1
        type: GAUGE
      - pattern : io.strimzi.kafka.quotas<type=StaticQuotaCallback, name=(.+)><>Value
        name: kafka_broker_client_quota_limit
        labels:
          quota_type: "$1"
        type: GAUGE
      - labels:
          clientID: $1
        name: kafka_producer_metrics_$2
        pattern: >-
          kafka.producer<type=producer-metrics, client-id=(.+)><>(outgoing-byte-rate|outgoing-byte-total)
        type: GAUGE
      - labels:
          clientID: $1
        name: kafka_producer_metrics_$2
        pattern: >-
          kafka.producer<type=producer-metrics, client-id=(.+)><>(connection-[\w-]*[\w])
        type: GAUGE
      - labels:
          clientID: $1
        name: kafka_consumer_metrics_$2
        pattern: >-
          kafka.consumer<type=consumer-metrics, client-id=(.+)><>(incoming-byte-rate|incoming-byte-total)
        type: GAUGE
      - labels:
          clientID: $1
        name: kafka_consumer_metrics_$2
        pattern: >-
          kafka.consumer<type=consumer-metrics, client-id=(.+)><>(connection-[\w-]*[\w])
        type: GAUGE
      - labels:
          clientID: $1
        name: kafka_adminclient_metrics_$2
        pattern: >-
          kafka.admin.client<type=admin-client-metrics, client-id=(.+)><>(connection-[\w-]*[\w])
        type: GAUGE
