Bird
Raised Fist0
Kafkadevops~10 mins

Prometheus and Grafana integration in Kafka - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to expose Kafka metrics for Prometheus scraping.

Kafka
metricsReporter = new [1]();
Drag options to blanks, or click blank then click option'
APrometheusReporter
BJmxReporter
CConsoleReporter
DSlf4jReporter
Attempts:
3 left
💡 Hint
Common Mistakes
Using JmxReporter which exposes JMX metrics but not Prometheus format.
Using ConsoleReporter which prints metrics to console only.
2fill in blank
medium

Complete the Prometheus scrape configuration to monitor Kafka metrics.

Kafka
- job_name: 'kafka'
  static_configs:
    - targets: ['[1]']
Drag options to blanks, or click blank then click option'
Alocalhost:7071
Blocalhost:9092
Clocalhost:8080
Dlocalhost:1234
Attempts:
3 left
💡 Hint
Common Mistakes
Using Kafka broker port 9092 which is for client connections, not metrics.
Using random ports like 8080 or 1234.
3fill in blank
hard

Fix the error in the Grafana data source URL for Prometheus.

Kafka
url = 'http://[1]/api/v1';
Drag options to blanks, or click blank then click option'
Alocalhost:9090
Bprometheus:8080
Cprometheus:9090
Dlocalhost:8081
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong port like 8080 or 8081.
Using localhost when Prometheus runs in a container named 'prometheus'.
4fill in blank
hard

Complete the code to create a Prometheus alert rule for Kafka consumer lag.

Kafka
alert: KafkaConsumerLagHigh
expr: kafka_consumer_lag > [1]
for: 5m
Drag options to blanks, or click blank then click option'
B1000
C100
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Adding operators like 'sum' directly after metric name.
Using too low threshold like 100 which may cause false alerts.
5fill in blank
hard

Fill all three blanks to configure Kafka JMX exporter for Prometheus.

Kafka
jmx_prometheus_javaagent=[1]=[2]:[3]
Drag options to blanks, or click blank then click option'
Ajavaagent.jar
Blocalhost
C7071
Dkafka-jmx-exporter.jar
Attempts:
3 left
💡 Hint
Common Mistakes
Using generic javaagent.jar instead of Kafka specific jar.
Wrong host or port for metrics endpoint.

Practice

(1/5)
1. What is the main role of Prometheus in Kafka monitoring when integrated with Grafana?
easy
A. To collect Kafka metrics by scraping the metrics endpoint
B. To display visual dashboards of Kafka metrics
C. To send alerts directly to Kafka topics
D. To store Kafka messages for backup

Solution

  1. Step 1: Understand Prometheus function

    Prometheus collects metrics by scraping endpoints exposed by applications like Kafka.
  2. Step 2: Differentiate roles of Prometheus and Grafana

    Grafana is used for visualization, not data collection.
  3. Final Answer:

    To collect Kafka metrics by scraping the metrics endpoint -> Option A
  4. Quick Check:

    Prometheus collects metrics = A [OK]
Hint: Remember: Prometheus collects, Grafana displays [OK]
Common Mistakes:
  • Confusing Grafana as the collector
  • Thinking Prometheus stores Kafka messages
  • Assuming Prometheus sends alerts to Kafka
2. Which of the following is the correct Prometheus scrape configuration snippet to monitor Kafka metrics exposed at port 9090?
easy
A. - job_name: 'kafka'\n static_configs:\n - targets: ['localhost:9090']
B. - job_name: 'kafka'\n static_configs:\n - targets: ['localhost:2181']
C. - job_name: 'kafka'\n static_configs:\n - targets: ['localhost:8080']
D. - job_name: 'kafka'\n static_configs:\n - targets: ['localhost:1234']

Solution

  1. Step 1: Identify Kafka metrics port

    Kafka metrics exporter commonly exposes metrics on port 9090.
  2. Step 2: Match correct target in Prometheus config

    Only - job_name: 'kafka'\n static_configs:\n - targets: ['localhost:9090'] uses port 9090, which is correct for scraping Kafka metrics.
  3. Final Answer:

    - job_name: 'kafka'\n static_configs:\n - targets: ['localhost:9090'] -> Option A
  4. Quick Check:

    Port 9090 for Kafka metrics = A [OK]
Hint: Kafka metrics usually on port 9090, check targets carefully [OK]
Common Mistakes:
  • Using Kafka broker port 2181 (Zookeeper port) instead of metrics port
  • Confusing HTTP ports like 8080 for metrics
  • Using random ports not related to Kafka metrics
3. Given this Prometheus query to monitor Kafka consumer lag:
sum(kafka_consumer_group_lag) by (group)
What output will this query produce?
medium
A. Current CPU usage of Kafka brokers
B. Total lag per consumer group as a number
C. Number of active Kafka brokers
D. List of all Kafka topics with their lag

Solution

  1. Step 1: Understand the metric and aggregation

    The metric kafka_consumer_group_lag measures lag per consumer group and partition. Summing by group aggregates lag per group.
  2. Step 2: Interpret the query output

    The query returns total lag number for each consumer group, not topics or CPU usage.
  3. Final Answer:

    Total lag per consumer group as a number -> Option B
  4. Quick Check:

    sum by group = total lag per group [OK]
Hint: sum(... by (group)) means total per group [OK]
Common Mistakes:
  • Thinking it lists topics instead of groups
  • Confusing lag with broker count
  • Assuming CPU metrics from Kafka lag metric
4. You configured Prometheus to scrape Kafka metrics but Grafana shows no data. Which is the most likely cause?
medium
A. Prometheus scrape interval is too short
B. Grafana dashboard is not connected to Prometheus
C. Kafka metrics endpoint is not exposed or unreachable
D. Kafka broker is down

Solution

  1. Step 1: Check Prometheus scraping setup

    If Kafka metrics endpoint is not exposed or unreachable, Prometheus cannot collect data.
  2. Step 2: Understand impact on Grafana

    Without data in Prometheus, Grafana dashboards show no metrics.
  3. Final Answer:

    Kafka metrics endpoint is not exposed or unreachable -> Option C
  4. Quick Check:

    No data means no scrape target reachable [OK]
Hint: No data? Check if metrics endpoint is reachable first [OK]
Common Mistakes:
  • Blaming Grafana connection before checking Prometheus data
  • Assuming Kafka broker down always causes no data
  • Thinking scrape interval too short causes no data
5. You want to create a Grafana dashboard showing Kafka broker CPU usage and consumer lag side by side. Which data sources and queries should you use?
hard
A. Connect Grafana to Prometheus; use queries kafka_cpu_usage and kafka_topic_lag
B. Connect Grafana directly to Kafka; use queries kafka_cpu and kafka_lag
C. Connect Grafana to Kafka Connect; use queries cpu_usage and consumer_lag
D. Connect Grafana to Prometheus; use queries kafka_broker_cpu_usage and sum(kafka_consumer_group_lag) by (group)

Solution

  1. Step 1: Identify correct data source for metrics

    Prometheus collects Kafka metrics; Grafana connects to Prometheus for queries.
  2. Step 2: Choose correct metric names and queries

    Common metrics are kafka_broker_cpu_usage and kafka_consumer_group_lag aggregated by group.
  3. Final Answer:

    Connect Grafana to Prometheus; use queries kafka_broker_cpu_usage and sum(kafka_consumer_group_lag) by (group) -> Option D
  4. Quick Check:

    Prometheus + correct queries = C [OK]
Hint: Grafana queries Prometheus metrics, not Kafka directly [OK]
Common Mistakes:
  • Trying to connect Grafana directly to Kafka brokers
  • Using wrong metric names or unaggregated lag
  • Confusing Kafka Connect with Kafka broker metrics
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard