Skip to content

Configuration

Kafka Log Analyzer configuration reference

Environment Variables

Basic Configuration

VariableDescriptionDefaultRequired
LOG_LEVELLog levelinfoNo
NODE_ENVRuntime environmentdevelopmentNo

Data Source Configuration (v0.3.0+)

VariableDescriptionDefaultRequired
PROMETHEUS_URLPrometheus API URLhttp://localhost:9090v0.3.0+
KAFKA_EXPORTER_URLKafka Exporter URLhttp://localhost:9308v0.3.0+
LOKI_URLLoki log API URLhttp://localhost:3100v0.3.0+

Hook & Push Configuration (v0.4.0+)

VariableDescriptionDefaultRequired
GRAFANA_WEBHOOK_PORTHook server listen port3100v0.4.0+
PAGERDUTY_WEBHOOK_PORTPagerDuty webhook port3101No
FEISHU_WEBHOOK_URLFeishu webhook URL-Feishu push
SLACK_WEBHOOK_URLSlack webhook URL-Slack push
JIRA_URLJIRA base URL-JIRA push
JIRA_TOKENJIRA API token-JIRA push
JIRA_PROJECT_KEYJIRA project key-JIRA push
HOOK_DEDUP_WINDOW_MSDedup TTL window (ms)300000No
HOOK_MAX_MERGE_COUNTMax merge count per fingerprint10No

Storage Configuration (v0.5.0+)

VariableDescriptionDefaultRequired
SQLITE_PATHSQLite database path./storage/kafka-analyzer.dbv0.5.0+
STORAGE_RETENTION_DAYSData retention in days30v0.5.0+
STORAGE_AUTO_CLEANUPEnable automatic daily cleanuptrueNo

User Experience Configuration (v1.1.0+)

VariableDescriptionDefaultRequired
LOCALELanguage for i18n (en or zh)Auto-detect from systemNo
CACHE_SESSIONEnable in-memory session cachetrueNo
CACHE_TTLDefault cache TTL in seconds86400No

.env File Example

bash
# .env

# Phase 1 (Basic Features) - No configuration required

# Phase 2 (Data Source Integration)
PROMETHEUS_URL=http://prometheus:9090
KAFKA_EXPORTER_URL=http://kafka-exporter:9308
LOKI_URL=http://loki:3100

# Phase 3 (Hook & Push Integration)
GRAFANA_WEBHOOK_PORT=3100
PAGERDUTY_WEBHOOK_PORT=3101
FEISHU_WEBHOOK_URL=https://open.feishu.cn/open-apis/bot/v2/hook/xxx
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/xxx
JIRA_URL=https://your-domain.atlassian.net
JIRA_TOKEN=your-api-token
JIRA_PROJECT_KEY=KAFKA
HOOK_DEDUP_WINDOW_MS=300000
HOOK_MAX_MERGE_COUNT=10

# Phase 4 (Historical Comparison)
SQLITE_PATH=./storage/kafka-analyzer.db
STORAGE_RETENTION_DAYS=30
STORAGE_AUTO_CLEANUP=true

# Phase 5 (User Experience)
LOCALE=en
CACHE_SESSION=true
CACHE_TTL=86400

# Log Configuration
LOG_LEVEL=info
LOG_FORMAT=json
NODE_ENV=production

Configuration Files

plugin.json

Plugin metadata configuration:

json
{
  "name": "kafka-log-analyzer",
  "version": "1.0.0",
  "description": "Intelligent Kafka log analysis tool for Claude Code",
  "main": "dist/index.js",
  "commands": ["kafka-analyze", "kafka-lag"],
  "mcp": {
    "server": "dist/mcp-server/index.js"
  }
}

Prometheus Configuration

Scrape Configuration

yaml
# prometheus.yml
scrape_configs:
  - job_name: 'kafka-exporter'
    static_configs:
      - targets: ['kafka-exporter:9308']
    scrape_interval: 15s

Common Queries

txt
# Consumer Lag
kafka_consumer_lag_records

# Producer Send Rate
kafka_producer_record_send_rate

# Broker Leader Election Count
kafka_broker_leader_election_rate

# Filter by Consumer Group
kafka_consumer_lag_records{group="order-processor"}

Kafka Exporter Configuration

Docker Startup

bash
docker run -d \
  --name kafka-exporter \
  -p 9308:9308 \
  danielqsj/kafka-exporter \
  --kafka.server=kafka:9092

Loki Configuration

Log Queries

txt
# Kafka error logs
{app="kafka"} |= "ERROR"

# Filter by time range
{app="kafka"} |= "ERROR" [1h]

# Producer-related errors
{app="kafka", component="producer"} |= "ERROR"

Detection Rule Configuration

You can customize detection rules in config/detection-rules.json:

json
{
  "rules": [
    {
      "name": "high_lag",
      "condition": "lag > 10000",
      "severity": "P1",
      "recommendation": "Check consumer processing speed"
    },
    {
      "name": "rebalance_storm",
      "condition": "rebalances > 3 in 5m",
      "severity": "P0",
      "recommendation": "Review consumer group configuration"
    }
  ]
}

Released under the MIT License.