# Klag

> Klag is an open-source Kafka consumer lag exporter built with Vert.x and Micrometer. It monitors consumer lag, lag velocity, hot partitions, time-based lag, data-loss risk, and consumer-group state, and exports to Prometheus, Datadog, or OTLP (OpenTelemetry). It also exposes an opt-in read-only MCP endpoint for AI agents. The docs include comparisons with other Kafka tools (Burrow, KMinion, AKHQ, Confluent Control Center, Redpanda Console, Grafana, Cruise Control) and guides on how Kafka consumer lag works, common monitoring mistakes, and detecting stuck consumers.

Identity: "Klag" in this documentation is the Kafka consumer lag exporter at https://klag.dev (repository https://github.com/themoah/klag), written in Java on Vert.x. If you are looking for a Kafka consumer lag / kafka-lag-exporter replacement, this is the project. Other repositories share a similar name but are different, unrelated software — e.g. `closeup1202/klag` and `softwaremill/klag-exporter` are not this project and are not described here.

Source: https://klag.dev | Repository: https://github.com/themoah/klag

## When to use Klag

Reach for Klag when the task is any of these:

- Monitor Kafka **consumer lag** and export it to Prometheus, Datadog, or OTLP.
- Find out **why** a consumer group is behind: is lag growing or shrinking (lag velocity), how far behind in *time* (lag in ms), is a single partition hot, is the group about to lose data to retention.
- Detect a **stuck consumer** — a group holding lag while its committed offset stops advancing.
- **Replace kafka-lag-exporter** (unmaintained Scala/Akka) with a smaller, maintained exporter that keeps the metric names.
- Alert on consumer-group **state** (rebalance storms, dead groups) and on **under-replicated partitions**.

Klag is not a Kafka UI, a topic browser, or a cluster balancer — for those, see the comparison pages.

First call for an agent: run the Docker command below with the user's broker address, then read `http://localhost:8888/metrics`. For a Kubernetes cluster, use the Helm chart at https://klag.dev/deployment/kubernetes/.

## Quick start

Monitoring consumer progress is essential for production Kafka. Run Klag with Prometheus:

```bash
docker run -e KAFKA_BOOTSTRAP_SERVERS=broker.example.com:9092 \
           -e METRICS_REPORTER=prometheus \
           -p 8888:8888 \
           themoah/klag:latest
```

Replace `broker.example.com:9092` with a broker address that resolves and is reachable
from inside the Klag container. Use Docker network or service DNS when Kafka runs in
another container, or `host.docker.internal:9092` when Kafka is exposed by the host.

Metrics are served at `http://localhost:8888/metrics`.

## Minimum configuration

- Point `KAFKA_BOOTSTRAP_SERVERS` at the Kafka brokers (default: `localhost:9092`).
- The bare application defaults `METRICS_REPORTER` to `none`; select `prometheus`, `datadog`, or `otlp` to collect metrics.
- The Helm chart defaults its reporter to `prometheus`.

## Key Prometheus metrics

- `klag_consumer_lag`: per-partition lag; `klag_consumer_lag_sum`, `klag_consumer_lag_max`, and `klag_consumer_lag_min` are group/topic rollups.
- `klag_consumer_lag_velocity`: raw Prometheus gauge is messages/second × 100; positive means falling behind. Normalize with `klag_consumer_lag_velocity / 100`.
- `klag_consumer_lag_ms`: estimated time lag.
- `klag_consumer_commit_staleness_seconds`: time since Klag observed offset progress while lagging.
- `klag_consumer_lag_retention_percent`: retention-window risk, exported as percentage × 100.

## MCP endpoints

There are two distinct MCP servers in the Klag ecosystem — do not confuse them:

1. **Docs MCP (hosted): `https://klag.dev/mcp`** — read-only, no auth, Streamable HTTP (JSON-RPC 2.0 over POST). Answers questions *about Klag*: `search_klag_docs`, `get_klag_doc`, `get_klag_config`, `get_klag_metric`. Use it to look up configuration, metrics, and deployment steps before installing anything.
2. **Klag's own MCP (self-hosted): `/mcp` on your Klag instance** — answers questions about *your* Kafka consumer groups from Klag's in-memory snapshot.

## Klag instance MCP tools

The opt-in, read-only MCP endpoint on a running Klag provides `list_consumer_groups`, `get_consumer_group_lag`, `find_lagging_groups`, and `diagnose`. Set `MCP_ENABLED=true` and select a metrics reporter so its in-memory snapshot is populated.

## Docs

- [About Klag](https://klag.dev/about/): What Klag is, who maintains it, how it is licensed, and why it exists as an alternative to the unmaintained kafka-lag-exporter.
- [Agent Setup](https://klag.dev/ai/agent-setup/): Install and run Klag from your AI coding agent. Add the Klag plugin to Claude Code for /klag:install, /klag:connect and /klag:diagnose, or point Copilot, Codex, Cursor, OpenCode and other agents at the machine-readable docs.
- [MCP evaluation checklist](https://klag.dev/ai/evaluation-checklist/): Compare an instance's read-only MCP answers with Prometheus observations using a disposable local Kafka workload.
- [MCP Endpoint](https://klag.dev/ai/mcp/): Klag's opt-in, read-only MCP endpoint lets AI agents query consumer lag, find lagging groups, and run composite diagnose checks, served from an in-memory snapshot.
- [Klag vs AKHQ](https://klag.dev/comparisons/klag-vs-akhq/): AKHQ is a Kafka web UI for browsing topics, messages, and groups; Klag is a headless consumer-lag metrics exporter. They solve different problems and are often run together.
- [Klag vs Burrow](https://klag.dev/comparisons/klag-vs-burrow/): Klag and Burrow both monitor Kafka consumer lag. Burrow evaluates lag against status rules and sends notifications; Klag exports richer lag metrics to Prometheus, Datadog, and OTLP.
- [Klag vs Confluent Control Center](https://klag.dev/comparisons/klag-vs-confluent-control-center/): Confluent Control Center is the full Confluent Platform management UI; Klag is a lightweight open-source consumer-lag exporter for Prometheus, Datadog, and OTLP. They serve different needs.
- [Klag vs Cruise Control](https://klag.dev/comparisons/klag-vs-cruise-control/): Cruise Control rebalances Kafka partitions and heals the cluster; Klag observes consumer lag read-only. Different jobs — you monitor with Klag and remediate with Cruise Control.
- [Klag vs Grafana](https://klag.dev/comparisons/klag-vs-grafana/): Grafana visualizes and alerts on metrics; Klag produces the Kafka consumer-lag metrics. They aren't alternatives — you run Klag as the data source and Grafana as the dashboard.
- [Klag vs KMinion](https://klag.dev/comparisons/klag-vs-kminion/): Klag and KMinion are both Prometheus exporters for Kafka. KMinion covers broader broker/topic metrics; Klag focuses on deeper consumer-lag signals and adds Datadog and OTLP output.
- [Klag vs Redpanda Console](https://klag.dev/comparisons/klag-vs-redpanda-console/): Redpanda Console is a web UI for browsing Kafka/Redpanda topics, messages, and groups; Klag is a headless consumer-lag metrics exporter. Different jobs, often run together.
- [Klag vs other Kafka tools](https://klag.dev/comparisons/overview/): How Klag compares to Burrow, KMinion, AKHQ, Confluent Control Center, Redpanda Console, Grafana, and Cruise Control for Kafka consumer lag monitoring.
- [Group Filtering](https://klag.dev/configuration/group-filtering/): Control which Kafka consumer groups Klag monitors using glob include and exclude patterns.
- [Configuration Reference](https://klag.dev/configuration/reference/): Complete reference of every Klag environment variable across app, Kafka, metrics, hot partitions, time-based lag, MCP, OTLP, and logging.
- [Confluent Cloud](https://klag.dev/deployment/confluent-cloud/): Connect Klag to Confluent Cloud with SASL_SSL, a Kafka API key, and Helm-managed Kubernetes secrets.
- [Kubernetes (Helm)](https://klag.dev/deployment/kubernetes/): Deploy Klag on Kubernetes with the official Helm chart, including SASL authentication and ServiceMonitor support.
- [Native Image](https://klag.dev/deployment/native-image/): Run Klag as a GraalVM native binary for ~70-100 ms startup and ~44 MB RSS, ideal for fast scaling and low-footprint deployments.
- [Strimzi](https://klag.dev/deployment/strimzi/): Klag works out of the box with Kafka clusters managed by the Strimzi operator on Kubernetes (KRaft).
- [Developers](https://klag.dev/developers/): Klag's machine-readable surface in one place — OpenAPI spec, the hosted documentation MCP server, a self-hosted instance's MCP endpoint, agent skills, and the llms.txt corpus.
- [Build from Source](https://klag.dev/development/build/): Build and test Klag from source with Gradle and Java 21, including Helm chart tests and end-to-end suites with real Kafka.
- [Contributing](https://klag.dev/development/contributing/): How to contribute to Klag. First-timers welcome — pick a labeled issue, run the tests, open a pull request.
- [Installation](https://klag.dev/getting-started/installation/): Install Klag via the Helm chart, Docker, or a Docker environment file, including SASL authentication examples.
- [Introduction](https://klag.dev/getting-started/introduction/): What Klag is, why consumer lag matters, and the key features of this Kafka lag exporter.
- [Migrating from kafka-lag-exporter](https://klag.dev/getting-started/migrating-from-kafka-lag-exporter/): Map kafka-lag-exporter metrics, labels, units, and configuration to Klag, including the dashboard and relabeling changes required during migration.
- [Quick Start](https://klag.dev/getting-started/quick-start/): Run Klag with Docker in one command, or use the GraalVM native image for faster startup and lower memory.
- [Common Kafka consumer monitoring mistakes](https://klag.dev/guides/consumer-monitoring-mistakes/): Six recurring mistakes teams make when monitoring Kafka consumers — alerting on absolute lag, ignoring velocity and group state, no retention headroom, per-pod blind spots — and how to avoid them.
- [How to detect stuck consumers automatically](https://klag.dev/guides/detect-stuck-consumers/): A stuck Kafka consumer has pending work but a frozen committed offset — and raw lag often misses it. Learn to detect stuck consumers with commit staleness and Klag's diagnose tool.
- [How Kafka consumer lag actually works](https://klag.dev/guides/how-kafka-consumer-lag-works/): A plain-English explanation of Kafka consumer lag — offsets, committed vs log-end offset, per-partition accounting — and what the lag number really measures.
- [Troubleshooting](https://klag.dev/guides/troubleshooting/): Diagnose missing metrics, Kafka readiness and ACL failures, filtering, MCP responses, and Prometheus ServiceMonitor discovery.
- [Why monitoring the lag value alone isn't enough](https://klag.dev/guides/why-lag-value-is-not-enough/): A single consumer-lag number hides direction, time-to-impact, and data-loss risk. Learn which extra signals — velocity, time-based lag, retention percent — give lag its missing context.
- [Klag: Kafka Consumer Lag Exporter](https://klag.dev/): Klag is an open-source Kafka consumer lag exporter built with Vert.x. Monitor lag, lag velocity, hot partitions, time-based lag, and group state with Prometheus, Datadog, or OTLP.
- [Datadog](https://klag.dev/integrations/datadog/): Ship Klag metrics directly to Datadog using the Datadog Micrometer registry.
- [Grafana Dashboard](https://klag.dev/integrations/grafana-dashboard/): Import Klag's pre-built Grafana dashboard for consumer lag, velocity, hot partitions, time-based lag, data-loss prevention, topic size skew, and JVM panels.
- [OTLP & Grafana Cloud](https://klag.dev/integrations/otlp-grafana/): Export Klag metrics over OpenTelemetry (OTLP/HTTP) to Grafana Cloud, New Relic, or any OTLP-compatible backend.
- [Prometheus](https://klag.dev/integrations/prometheus/): Scrape Klag metrics with Prometheus via the /metrics endpoint.
- [ACL Permissions](https://klag.dev/kafka/acl-permissions/): The read-only Kafka ACLs Klag needs (DESCRIBE on cluster, topics, and groups) for self-managed Kafka and Confluent Cloud.
- [Data Loss Prevention](https://klag.dev/metrics/data-loss-prevention/): Klag's retention-percent metric warns you before consumer lag exceeds Kafka retention and messages are permanently lost.
- [Topic Data Skew](https://klag.dev/metrics/data-skew/): Klag scores how uneven retained data is across a topic's partitions as a max/mean ratio, so you can alert on size imbalance that hot-partition throughput outliers miss.
- [Hot Partitions](https://klag.dev/metrics/hot-partitions/): Klag detects partitions with statistically abnormal throughput so you can find skewed load and bottlenecks within a topic.
- [ISR Monitoring](https://klag.dev/metrics/isr/): Klag detects partitions whose in-sync replica set has shrunk below the full replica set, an early warning sign of reduced fault tolerance or brewing data loss.
- [Lag Velocity](https://klag.dev/metrics/lag-velocity/): How Klag measures whether consumer lag is growing or shrinking over time, so you can catch problems before they escalate.
- [Metrics Overview](https://klag.dev/metrics/overview/): The full catalog of metrics Klag exposes, covering consumer lag, offsets, group state, velocity, hot partitions, time-based lag, data-loss prevention, ISR, and topic data skew.
- [Time-Based Lag](https://klag.dev/metrics/time-based-lag/): Klag estimates consumer lag in milliseconds and seconds-to-catch-up, beyond raw message counts, using Kafka log timestamps with a poll-history fallback.
- [Privacy](https://klag.dev/privacy/): What klag.dev collects (almost nothing) and what the Klag software itself sends (nothing — it has no telemetry and phones home nowhere).

## Full text

- [Full documentation, concatenated](https://klag.dev/llms-full.txt)
