Skip to content

Bowl42/claude-code-grafana

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Claude Code Grafana Dashboard

A comprehensive Grafana dashboard for monitoring Claude Code usage via OpenTelemetry.

Grafana 10+ Prometheus Loki

Panels

Prometheus Metrics

  • Overview — Sessions, Cost (24h), Tokens (24h), Lines Changed, Commits, Active Time
  • Cost & Tokens — Cost by model, token usage by type (input/output/cache)
  • Activity — Lines of code changed, sessions/commits/PRs over time
  • Active Time & Tokens by Model — Active time breakdown, tokens per model
  • Tool Decisions — Edit tool decisions by tool name, language, and source
  • Cumulative — Running total cost and token counters

Loki Events (optional)

  • API request count, errors, and latency
  • Tool usage frequency and duration
  • Per-request cost and token breakdown (input/output/cache read/cache creation)
  • Formatted event log viewer

Prerequisites

  1. Claude Code with OTel telemetry enabled
  2. OpenTelemetry Collector (Alloy, otel-collector, etc.) receiving OTLP and forwarding to Prometheus
  3. Prometheus datasource in Grafana
  4. Loki datasource in Grafana (optional, for the Events section)

Setup

1. Enable Claude Code Telemetry

Add the following to ~/.claude/settings.json:

{
  "env": {
    "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
    "OTEL_METRICS_EXPORTER": "otlp",
    "OTEL_LOGS_EXPORTER": "otlp",
    "OTEL_EXPORTER_OTLP_PROTOCOL": "grpc",
    "OTEL_EXPORTER_OTLP_ENDPOINT": "http://<your-collector>:4317",
    "OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE": "cumulative"
  }
}

Note: Restart Claude Code after changing settings.json — environment variables are only loaded at process startup.

See the official docs for more details.

2. Import the Dashboard

Option A — File upload:

  1. Open Grafana → Dashboards → Import
  2. Upload dashboard.json
  3. Select your Prometheus and Loki datasources

Option B — Grafana.com ID:

Coming soon.

Metrics Reference

Metric Description Labels
claude_code_session_count_total Number of sessions started
claude_code_cost_usage_USD_total Cost in USD model
claude_code_token_usage_tokens_total Token count model, type
claude_code_lines_of_code_count_total Lines of code changed type
claude_code_commit_count_total Git commits made
claude_code_pull_request_count_total Pull requests created
claude_code_active_time_seconds_total Active coding time type
claude_code_code_edit_tool_decision_total Edit tool decisions tool_name, decision, language, source

Loki Events

If your collector forwards OTel logs to Loki, the Events section displays:

Event Key Attributes
api_request model, cost_usd, duration_ms, input_tokens, output_tokens, cache_read_tokens
api_error error, status_code
tool_result tool_name, success, duration_ms
tool_decision tool_name, decision
user_prompt prompt_length

License

MIT

About

Grafana dashboard for monitoring Claude Code via OpenTelemetry (Prometheus + Loki)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors