Kafka Consumer Lag 标志

Kafka Consumer Lag

组织
lensesio
kafka-consumer-lag

使用 Lenses MCP 服务器分析 Kafka 消费者组延迟。诊断延迟原因(吞吐量瓶颈、重新平衡、分区倾斜、消费者停滞),并提出解决建议。当用户说“检查消费者延迟”“消费者为什么这么慢”“延迟报告”,或询问消费者组健康状况或偏移量进度时使用。请勿用于重置偏移量或管理消费者组。

Add to TypingMind

概览

发布者lensesio
代码仓库agentic-engineering-for-apache-kafka
技能名称kafka-consumer-lag
星标数
67
复刻数
19
附带文件
1
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 1 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 lensesio 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Kafka Consumer Lag AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/lensesio/agentic-engineering-for-apache-kafka/tree/main/skills/kafka-consumer-lag
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/lensesio/agentic-engineering-for-apache-kafka.git /tmp/agentic-engineering-for-apache-kafka
mkdir -p .claude/skills
cp -r /tmp/agentic-engineering-for-apache-kafka/skills/kafka-consumer-lag .claude/skills/kafka-consumer-lag
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Kafka Consumer Lag,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Kafka Consumer Lag。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Kafka Consumer Lag 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Kafka Consumer Lag Analysis

Analyses consumer group lag across all groups and diagnoses potential causes. Consumer lag is the most commonly monitored Kafka metric and the first thing engineers check during incidents.

Target environment: $ARGUMENTS

Workflow

Copy this checklist and track your progress:

Lag Analysis Progress:
- [ ] Step 1: Fetch all consumer groups
- [ ] Step 2: Identify problematic groups
- [ ] Step 3: Diagnose root causes
- [ ] Step 4: Generate report
  1. Fetch all consumer groups with state and lag info
  2. Identify problematic groups (high lag, idle, rebalancing)
  3. Diagnose root causes using partition and throughput data
  4. Report findings with per-group remediation steps

Step 1: Fetch Consumer Groups

Use the Lenses MCP list_consumer_groups tool to get all consumer groups with:

  • Group state (Stable, Rebalancing, Empty, Dead)
  • Lag per topic-partition
  • Active member count
  • Coordinator info

For topic-specific analysis, use list_consumer_groups_by_topic to narrow the scope.

Expected output: List of all consumer groups with state, lag and member count.

Validation: If no consumer groups are returned, report this finding and stop - the cluster may have no active consumers.

Step 2: Identify Problematic Groups

Flag consumer groups in these categories:

Critical

  • Groups in Dead or Empty state with committed offsets (consumer has stopped)
  • Groups with lag growing over time (compare current lag against partition end offsets using get_topic_partitions)

Warning

  • Groups in Rebalancing state (consumption paused)
  • Groups with uneven partition assignment (some consumers have significantly more partitions than others)
  • Groups with no committed offsets (consumer may never have started successfully)

Suggestion

  • Groups with very high member count relative to partition count (idle consumers)
  • Groups consuming from topics with no recent messages (use get_dataset_message_metrics to check producer throughput)

Step 3: Diagnose Root Causes

For each problematic group, determine the likely cause:

Growing Lag + Stable Producer Rate

  • Consumer throughput bottleneck
  • Remediation: Scale consumers, increase max.poll.records, reduce processing time per message, check for synchronous blocking calls

Lag Spikes + Rebalancing

  • Rebalancing is pausing consumption
  • Remediation: Switch to cooperative sticky assignor, increase session.timeout.ms, reduce max.poll.interval.ms risk

Single-Partition Lag (others are fine)

  • Hot partition / key skew
  • Remediation: Review partitioning strategy, check for hot keys, consider custom partitioner

All Partitions Lagging Equally

  • Overall consumer slowness
  • Remediation: Profile consumer processing, check for external dependencies (database, API calls), increase consumer instances

Zero Lag but Empty Group

  • Consumer crashed or was decommissioned
  • Remediation: Check consumer process health, restart if needed, clean up stale groups

Step 4: Verify Data Flow

Use the Lenses MCP execute_sql tool to sample recent messages from lagging topics:

sql
SELECT * FROM {topic} LIMIT 5

This confirms the topic has active producers and messages are flowing.

Success Criteria

Quantitative

  • Triggers on 90% of lag-related queries (test with 10-20 varied phrasings)
  • Completes analysis in under 12 MCP tool calls
  • 0 failed MCP calls per run

Qualitative

  • Each flagged group has a specific diagnosis and remediation
  • Report distinguishes symptom from root cause
  • Consistent results when re-run on the same environment

Examples

Example 1: Incident investigation

User says: "Consumers are falling behind, check the lag"

Actions:

  1. Fetch all consumer groups for the environment
  2. Sort by total lag descending to find the worst offenders
  3. Diagnose root causes for each critical group Result: Prioritised report with per-group diagnosis and remediation

Example 2: Topic-specific lag check

User says: "Check consumer lag for orders.payment.completed"

Actions:

  1. Use list_consumer_groups_by_topic to get groups consuming from that topic
  2. Check partition-level lag distribution
  3. Verify data flow with execute_sql Result: Focused report on a single topic's consumer groups

Example 3: Stale group cleanup

User says: "Find any dead or empty consumer groups"

Actions:

  1. Fetch all consumer groups
  2. Filter for Dead or Empty state with committed offsets
  3. Report stale groups that can be safely cleaned up Result: List of candidate groups for deletion

Troubleshooting

Consumer groups list is empty

Cause: No consumer groups exist in the environment or permissions are restricted. Solution: Verify consumers are running. Check Lenses agent permissions allow listing consumer groups.

Lag numbers seem incorrect

Cause: Consumer group offsets may be stale if the consumer recently stopped. Solution: Compare lag against partition end offsets from get_topic_partitions. Note when offsets were last committed.

execute_sql returns no data

Cause: Topic is empty or has very old messages beyond the query window. Solution: Use get_dataset_message_metrics to check if the topic has recent throughput. An empty topic with lagging consumers indicates a producer issue.

Output Format

## Consumer Lag Report

### Environment: {name}

### Critical (immediate action)
| Consumer Group | Topic | Total Lag | State | Diagnosis | Remediation |
|---------------|-------|-----------|-------|-----------|-------------|
| group-name | topic | 50000 | Stable | Throughput bottleneck | Scale consumers |

### Warning (investigate)
| Consumer Group | Topic | Total Lag | State | Diagnosis | Remediation |
|---------------|-------|-----------|-------|-----------|-------------|

### Suggestion (optimise)
| Consumer Group | Topic | Total Lag | State | Diagnosis | Remediation |
|---------------|-------|-----------|-------|-----------|-------------|

### Summary
- X consumer groups analysed
- Y groups with critical lag
- Z groups with warnings
- Stale/empty groups: N

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Kafka Consumer Lag AI 技能有什么作用?

使用 Lenses MCP 服务器分析 Kafka 消费者组延迟。诊断延迟原因(吞吐量瓶颈、重新平衡、分区倾斜、消费者停滞),并提出解决建议。当用户说“检查消费者延迟”“消费者为什么这么慢”“延迟报告”,或询问消费者组健康状况或偏移量进度时使用。请勿用于重置偏移量或管理消费者组。

为什么在 TypingMind 中使用 Kafka Consumer Lag?

因为您只需安装一次,就能搭配任何模型使用。Kafka Consumer Lag 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Kafka Consumer Lag?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/lensesio/agentic-engineering-for-apache-kafka/tree/main/skills/kafka-consumer-lag。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Kafka Consumer Lag?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Kafka Consumer Lag 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Kafka Consumer Lag 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Kafka Consumer Lag AI 技能免费吗?

是的。lensesio 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇