Skip to content

规则

yaml

groups:
- name: Kafka_Alerts
  rules:
    - alert: Offline_Partiton_Count
      expr: sum(kafka_controller_KafkaController_OfflinePartitionsCount{executor_name="kafka"})by(service_name)  > 0
      for: 1m
      labels:
        severity: critical
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: {{ $value }} partitons offline'
        description: 'After successful leader election, if the leader for partition dies, then the partition moves to the OfflinePartition state. Offline partitions are not available for reading and writing. Restart the brokers, if needed, and check the logs for errors.'

    - alert: Under_Replicated_Partition_Count
      expr: sum(kafka_server_ReplicaManager_UnderReplicatedPartitions{executor_name="kafka"})by(service_name) > 0
      for: 1m
      labels:
        severity: critical
      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.'

    - alert: Active_Controller
      expr: sum(kafka_controller_KafkaController_ActiveControllerCount{executor_name="kafka"})by(service_name) != 1
      for: 1m
      labels:
        severity: critical
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: No active controller'
        description: 'No broker in the cluster is reporting as the active controller in the last 1 minute interval. During steady state there should be only one active controller per cluster.'

    - alert: Unclean_Leader_Election
      expr: max(kafka_controller_ControllerStats_UncleanLeaderElectionsPerSec_5MinuteRate{executor_name="kafka"})by(service_name) != 0
      for: 1m
      labels:
        severity: critical
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: {{ $value }} unclean leader elections'
        description: '{{ $value }} unclean partition leader elections in the cluster reported in the last 1 minute interval. When unclean leader election is held among out-of-sync replicas, there is a possibility of data loss if any messages were not synced prior to the loss of the former leader. So if the number of unclean elections is greater than 0, investigate broker logs to determine why leaders were re-elected, and look for WARN or ERROR messages. Consider setting the broker configuration parameter unclean.leader.election.enable to false so that a replica outside of the set of in-sync replicas is never elected leader.'

    - alert: ISR_Expand_Rate
      expr: sum(kafka_server_ReplicaManager_IsrExpandsPerSec_5MinuteRate)by(service_name) != 0
      for: 1m
      labels:
        severity: warning
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: {{ $value }} ISR Expansion Rate'
        description: 'If a broker goes down, ISR for some of the partitions shrink. When that broker is up again, ISRs are expanded once the replicas are fully caught up. Other than that, the expected value for ISR expansion rate is 0. If ISR is expanding and shrinking frequently, adjust Allowed replica lag.'

    - alert: ISR_Shrink_Rate
      expr: sum(kafka_server_ReplicaManager_IsrShrinksPerSec_5MinuteRate)by(service_name) != 0
      for: 1m
      labels:
        severity: warning
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: {{ $value }} ISR Shrink Rate'
        description: 'If a broker goes down, ISR for some of the partitions shrink. When that broker is up again, ISRs are expanded once the replicas are fully caught up. Other than that, the expected value for ISR shrink rate is 0. If ISR is expanding and shrinking frequently, adjust Allowed replica lag.'

    - alert: Broker_Count
      expr: count(kafka_server_KafkaServer_BrokerState{executor_name="kafka"})by(service_name) == 0
      for: 1m
      labels:
        severity: critical
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: No Brokers online!'
        description: 'Broker count is 0'

    - alert: Network_Processor_Idle_Percent
      expr: avg(sum(kafka_network_Processor_IdlePercent{executor_name="kafka"})by(service_name, task_name))by(service_name) < 0.3
      for: 1m
      labels:
        severity: critical
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: Network Processor Idle Percent is {{ $value }}!'
        description: 'The average fraction of time the network processors are idle. A lower value {{ $value }} indicates that the network workload of the broker is very high.'

    - alert: Request_Handler_Idle_Percent
      expr: avg(kafka_server_KafkaRequestHandlerPool_RequestHandlerAvgIdlePercent_meanRate)by(service_name) < 0.3
      for: 1m
      labels:
        severity: critical
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: Request Handler Idle Percent is {{ $value }}!'
        description: 'The average fraction of time the request handler threads (IO) are idle. A lower value {{ $value }} indicates that the workload of a broker is very high.'

    - alert: Replica_Fetcher_Manager_Max_Lag
      expr: avg(kafka_server_ReplicaFetcherManager_MaxLag)by(service_name) > 50
      for: 1m
      labels:
        severity: critical
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: Replica Fetcher Manager Max Lag is {{ $value }}!'
        description: 'The maximum lag between the time that messages are received by the leader replica and by the follower replicas.'

    - alert: Topic_Count
      expr: count(count by (topic,service_name) (kafka_server_BrokerTopicMetrics_MessagesInPerSec_5MinuteRate{executor_name="kafka"}))by(service_name) > 1000
      for: 5m
      labels:
        severity: warning
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: 1000 topics reached'
        description: 'The number of active topics in the cluster has reached 1000.'
    
    - alert: Request_Queue_Time_Max
      expr: max(kafka_network_RequestMetrics_RequestQueueTimeMs_mean{executor_name="kafka"})by(service_name) > 100
      for: 1m
      labels:
        severity: warning
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: {{ $value }}ms request queue time'
        description: 'Max request queue time exceeded 100ms for a request. It is the time, in milliseconds, that a request currently spends in the request queue.'

    - alert: Response_Queue_Time_Max
      expr: max(kafka_network_RequestMetrics_ResponseQueueTimeMs_mean{executor_name="kafka"})by(service_name) > 100
      for: 1m
      labels:
        severity: warning
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: {{ $value }}ms response queue time'
        description: 'Max response queue time exceeded 100ms for a request. It is the length of time, in milliseconds, that the request waits in the response queue.'

    - alert: Zookeeper_Sync_Connect
      expr: avg(kafka_server_SessionExpireListener_ZooKeeperSyncConnectsPerSec_count{executor_name="kafka"})by(service_name) < 1
      for: 1m
      labels:
        severity: warning
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: Zookeeper Sync Disconected'
        description: 'Zookeeper Sync Disconected'

groups:
- name: Kafka_Alerts
  rules:
    - alert: Offline_Partiton_Count
      expr: sum(kafka_controller_KafkaController_OfflinePartitionsCount{executor_name="kafka"})by(service_name)  > 0
      for: 1m
      labels:
        severity: critical
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: {{ $value }} partitons offline'
        description: 'After successful leader election, if the leader for partition dies, then the partition moves to the OfflinePartition state. Offline partitions are not available for reading and writing. Restart the brokers, if needed, and check the logs for errors.'

    - alert: Under_Replicated_Partition_Count
      expr: sum(kafka_server_ReplicaManager_UnderReplicatedPartitions{executor_name="kafka"})by(service_name) > 0
      for: 1m
      labels:
        severity: critical
      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.'

    - alert: Active_Controller
      expr: sum(kafka_controller_KafkaController_ActiveControllerCount{executor_name="kafka"})by(service_name) != 1
      for: 1m
      labels:
        severity: critical
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: No active controller'
        description: 'No broker in the cluster is reporting as the active controller in the last 1 minute interval. During steady state there should be only one active controller per cluster.'

    - alert: Unclean_Leader_Election
      expr: max(kafka_controller_ControllerStats_UncleanLeaderElectionsPerSec_5MinuteRate{executor_name="kafka"})by(service_name) != 0
      for: 1m
      labels:
        severity: critical
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: {{ $value }} unclean leader elections'
        description: '{{ $value }} unclean partition leader elections in the cluster reported in the last 1 minute interval. When unclean leader election is held among out-of-sync replicas, there is a possibility of data loss if any messages were not synced prior to the loss of the former leader. So if the number of unclean elections is greater than 0, investigate broker logs to determine why leaders were re-elected, and look for WARN or ERROR messages. Consider setting the broker configuration parameter unclean.leader.election.enable to false so that a replica outside of the set of in-sync replicas is never elected leader.'

    - alert: ISR_Expand_Rate
      expr: sum(kafka_server_ReplicaManager_IsrExpandsPerSec_5MinuteRate)by(service_name) != 0
      for: 1m
      labels:
        severity: warning
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: {{ $value }} ISR Expansion Rate'
        description: 'If a broker goes down, ISR for some of the partitions shrink. When that broker is up again, ISRs are expanded once the replicas are fully caught up. Other than that, the expected value for ISR expansion rate is 0. If ISR is expanding and shrinking frequently, adjust Allowed replica lag.'

    - alert: ISR_Shrink_Rate
      expr: sum(kafka_server_ReplicaManager_IsrShrinksPerSec_5MinuteRate)by(service_name) != 0
      for: 1m
      labels:
        severity: warning
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: {{ $value }} ISR Shrink Rate'
        description: 'If a broker goes down, ISR for some of the partitions shrink. When that broker is up again, ISRs are expanded once the replicas are fully caught up. Other than that, the expected value for ISR shrink rate is 0. If ISR is expanding and shrinking frequently, adjust Allowed replica lag.'

    - alert: Broker_Count
      expr: count(kafka_server_KafkaServer_BrokerState{executor_name="kafka"})by(service_name) == 0
      for: 1m
      labels:
        severity: critical
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: No Brokers online!'
        description: 'Broker count is 0'

    - alert: Network_Processor_Idle_Percent
      expr: avg(sum(kafka_network_Processor_IdlePercent{executor_name="kafka"})by(service_name, task_name))by(service_name) < 0.3
      for: 1m
      labels:
        severity: critical
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: Network Processor Idle Percent is {{ $value }}!'
        description: 'The average fraction of time the network processors are idle. A lower value {{ $value }} indicates that the network workload of the broker is very high.'

    - alert: Request_Handler_Idle_Percent
      expr: avg(kafka_server_KafkaRequestHandlerPool_RequestHandlerAvgIdlePercent_meanRate)by(service_name) < 0.3
      for: 1m
      labels:
        severity: critical
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: Request Handler Idle Percent is {{ $value }}!'
        description: 'The average fraction of time the request handler threads (IO) are idle. A lower value {{ $value }} indicates that the workload of a broker is very high.'

    - alert: Replica_Fetcher_Manager_Max_Lag
      expr: avg(kafka_server_ReplicaFetcherManager_MaxLag)by(service_name) > 50
      for: 1m
      labels:
        severity: critical
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: Replica Fetcher Manager Max Lag is {{ $value }}!'
        description: 'The maximum lag between the time that messages are received by the leader replica and by the follower replicas.'

    - alert: Topic_Count
      expr: count(count by (topic,service_name) (kafka_server_BrokerTopicMetrics_MessagesInPerSec_5MinuteRate{executor_name="kafka"}))by(service_name) > 1000
      for: 5m
      labels:
        severity: warning
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: 1000 topics reached'
        description: 'The number of active topics in the cluster has reached 1000.'
    
    - alert: Request_Queue_Time_Max
      expr: max(kafka_network_RequestMetrics_RequestQueueTimeMs_mean{executor_name="kafka"})by(service_name) > 100
      for: 1m
      labels:
        severity: warning
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: {{ $value }}ms request queue time'
        description: 'Max request queue time exceeded 100ms for a request. It is the time, in milliseconds, that a request currently spends in the request queue.'

    - alert: Response_Queue_Time_Max
      expr: max(kafka_network_RequestMetrics_ResponseQueueTimeMs_mean{executor_name="kafka"})by(service_name) > 100
      for: 1m
      labels:
        severity: warning
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: {{ $value }}ms response queue time'
        description: 'Max response queue time exceeded 100ms for a request. It is the length of time, in milliseconds, that the request waits in the response queue.'

    - alert: Zookeeper_Sync_Connect
      expr: avg(kafka_server_SessionExpireListener_ZooKeeperSyncConnectsPerSec_count{executor_name="kafka"})by(service_name) < 1
      for: 1m
      labels:
        severity: warning
      annotations:
        summary: 'Kafka {{ $labels.service_name }}: Zookeeper Sync Disconected'
        description: 'Zookeeper Sync Disconected'