Last active
July 20, 2025 11:52
-
-
Save xtang/9005e501c5df9425587d3562534d047c to your computer and use it in GitHub Desktop.
Perses config for monitoring Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"kind": "Dashboard", | |
"metadata": { | |
"name": "claude-code-personal", | |
"project": "default", | |
"version": 1 | |
}, | |
"spec": { | |
"display": { | |
"name": "Claude Code Personal Usage Dashboard" | |
}, | |
"panels": { | |
"lines_of_code_today": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Lines of Code" | |
}, | |
"plugin": { | |
"kind": "StatChart", | |
"spec": { | |
"calculation": "last", | |
"format": { | |
"unit": "decimal", | |
"shortValues": false | |
} | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_lines_of_code_count{user_email=\"$user\"}[$timerange])) by (type)", | |
"seriesNameFormat": "{{type}}" | |
} | |
} | |
} | |
}, | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_commit_count{user_email=\"$user\"}[$timerange]))", | |
"seriesNameFormat": "Commit" | |
} | |
} | |
} | |
}, | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_pull_request_count{user_email=\"$user\"}[$timerange]))", | |
"seriesNameFormat": "PRs" | |
} | |
} | |
} | |
} | |
] | |
} | |
}, | |
"my_cost_today": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "My Cost (USD)" | |
}, | |
"plugin": { | |
"kind": "StatChart", | |
"spec": { | |
"calculation": "last", | |
"format": { | |
"unit": "decimal", | |
"decimalPlaces": 2, | |
"prefix": "$", | |
"shortValues": true | |
}, | |
"metricLabel": "$" | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_cost_usage{user_email=\"$user\", model=~\"$model\"}[$timerange]))" | |
} | |
} | |
} | |
} | |
] | |
} | |
}, | |
"tokens_used_today": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Tokens Used (Exclude Haiku)" | |
}, | |
"plugin": { | |
"kind": "StatChart", | |
"spec": { | |
"calculation": "last", | |
"format": { | |
"unit": "decimal", | |
"shortValues": false | |
} | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_token_usage{user_email=\"$user\", model!~\".*haiku.*\"}[$timerange])) by (type)", | |
"seriesNameFormat": "{{type}}" | |
} | |
} | |
} | |
} | |
] | |
} | |
}, | |
"code_efficiency": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Code Efficiency (Lines/$)" | |
}, | |
"plugin": { | |
"kind": "StatChart", | |
"spec": { | |
"calculation": "last", | |
"format": { | |
"unit": "decimal", | |
"decimalPlaces": 1 | |
}, | |
"sparkline": { | |
"color": "#ab47bc" | |
} | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_lines_of_code_count{user_email=\"$user\", model=~\"$model\"}[$timerange])) / sum(sum_over_time(claude_code_cost_usage{user_email=\"$user\", model=~\"$model\"}[$timerange]))" | |
} | |
} | |
} | |
} | |
] | |
} | |
}, | |
"lines_of_code_trend": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Lines of Code Trend " | |
}, | |
"plugin": { | |
"kind": "TimeSeriesChart", | |
"spec": { | |
"legend": { | |
"position": "bottom", | |
"mode": "list" | |
}, | |
"yAxis": { | |
"show": true, | |
"label": "lines", | |
"format": { | |
"unit": "decimal" | |
} | |
}, | |
"visual": { | |
"lineWidth": 1.25, | |
"areaOpacity": 0.15, | |
"pointRadius": 2.75, | |
"connectNulls": false, | |
"display": "line" | |
} | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_lines_of_code_count{user_email=\"$user\", type=\"added\"}[4h]))", | |
"minStep": "1h", | |
"seriesNameFormat": "added" | |
} | |
} | |
} | |
}, | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "-sum(sum_over_time(claude_code_lines_of_code_count{user_email=\"$user\", type=\"removed\"}[4h]))", | |
"seriesNameFormat": "removed", | |
"minStep": "1h" | |
} | |
} | |
} | |
} | |
], | |
"links": [] | |
} | |
}, | |
"hourly_code_output": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Hourly Code Output" | |
}, | |
"plugin": { | |
"kind": "BarChart", | |
"spec": { | |
"mode": "vertical", | |
"calculation": "last" | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_lines_of_code_count{user_email=\"$user\"}[1h])) by (type)", | |
"seriesNameFormat": "{{type}}" | |
} | |
} | |
} | |
} | |
] | |
} | |
}, | |
"cost_per_100_lines": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Opus Token Usage Breakdown (Daily)" | |
}, | |
"plugin": { | |
"kind": "BarChart", | |
"spec": { | |
"calculation": "last", | |
"format": { | |
"unit": "decimal", | |
"shortValues": true | |
}, | |
"sort": "desc", | |
"mode": "value" | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": " sum by (type) (\n sum_over_time(claude_code_token_usage{user_email=\"$user\", model=~\".*opus.*\"}[24h])\n )", | |
"seriesNameFormat": "{{type}}", | |
"minStep": "" | |
} | |
} | |
} | |
} | |
], | |
"links": [] | |
} | |
}, | |
"cost_per_100_lines-1": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Token Usage Breakdown by Model (Hourly)" | |
}, | |
"plugin": { | |
"kind": "TimeSeriesChart", | |
"spec": { | |
"visual": { | |
"lineWidth": 1.25, | |
"areaOpacity": 0.3, | |
"pointRadius": 2.75, | |
"connectNulls": false, | |
"display": "bar", | |
"stack": "all" | |
}, | |
"legend": { | |
"position": "bottom" | |
} | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_token_usage{user_email=\"$user\"}[1h])) by (model)", | |
"minStep": "1h", | |
"seriesNameFormat": "{{model}}" | |
} | |
} | |
} | |
} | |
], | |
"links": [] | |
} | |
}, | |
"cost_per_100_lines-3": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Cost Usage Breakdown by Model (Hourly)" | |
}, | |
"plugin": { | |
"kind": "TimeSeriesChart", | |
"spec": { | |
"visual": { | |
"lineWidth": 1.25, | |
"areaOpacity": 0.3, | |
"pointRadius": 2.75, | |
"connectNulls": false, | |
"display": "bar", | |
"stack": "all" | |
}, | |
"legend": { | |
"position": "bottom" | |
} | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_cost_usage{user_email=\"$user\"}[1h])) by (model)", | |
"minStep": "1h", | |
"seriesNameFormat": "{{model}}" | |
} | |
} | |
} | |
} | |
], | |
"links": [] | |
} | |
}, | |
"SessionCounterofToday": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Session Count" | |
}, | |
"plugin": { | |
"kind": "StatChart", | |
"spec": { | |
"calculation": "last-number", | |
"format": { | |
"unit": "decimal" | |
} | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_session_count{user_email=\"$user\"}[$timerange]))" | |
} | |
} | |
} | |
} | |
] | |
} | |
}, | |
"cost_per_100_lines-4": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Sonnet Token Usage Breakdown (Daily)" | |
}, | |
"plugin": { | |
"kind": "BarChart", | |
"spec": { | |
"calculation": "last", | |
"format": { | |
"unit": "decimal", | |
"shortValues": true | |
}, | |
"sort": "desc", | |
"mode": "value" | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": " sum by (type) (\n sum_over_time(claude_code_token_usage{user_email=\"$user\", model=~\".*sonnet.*\"}[24h])\n )", | |
"seriesNameFormat": "{{type}}", | |
"minStep": "" | |
} | |
} | |
} | |
} | |
], | |
"links": [] | |
} | |
}, | |
"cost_per_100_lines-5": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Haiku Token Usage Breakdown (Daily)" | |
}, | |
"plugin": { | |
"kind": "BarChart", | |
"spec": { | |
"calculation": "last", | |
"format": { | |
"unit": "decimal", | |
"shortValues": true | |
}, | |
"sort": "desc", | |
"mode": "value" | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": " sum by (type) (\n sum_over_time(claude_code_token_usage{user_email=\"$user\", model=~\".*haiku.*\"}[24h])\n )", | |
"seriesNameFormat": "{{type}}", | |
"minStep": "" | |
} | |
} | |
} | |
} | |
], | |
"links": [] | |
} | |
}, | |
"hourly_code_output-1": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Tool Decision Accept" | |
}, | |
"plugin": { | |
"kind": "BarChart", | |
"spec": { | |
"mode": "vertical", | |
"calculation": "last" | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_code_edit_tool_decision{user_email=\"$user\", decision=\"accept\"}[24h])) by (tool_name)", | |
"seriesNameFormat": "{{tool_name}}" | |
} | |
} | |
} | |
} | |
] | |
} | |
}, | |
"lines_of_code_trend-1": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Active Time by Sessions" | |
}, | |
"plugin": { | |
"kind": "TimeSeriesChart", | |
"spec": { | |
"legend": { | |
"position": "bottom", | |
"mode": "list" | |
}, | |
"yAxis": { | |
"show": true, | |
"label": "", | |
"format": { | |
"unit": "seconds" | |
} | |
}, | |
"visual": { | |
"lineWidth": 1.25, | |
"areaOpacity": 0.15, | |
"pointRadius": 2.75, | |
"connectNulls": false, | |
"display": "bar", | |
"stack": "all" | |
} | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_active_time_total{user_email=\"$user\"}[4h])) by (session_id)", | |
"minStep": "1h", | |
"seriesNameFormat": "{{session_id}}" | |
} | |
} | |
} | |
} | |
], | |
"links": [] | |
} | |
}, | |
"Cost/Session": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Cost per Session" | |
}, | |
"plugin": { | |
"kind": "TimeSeriesChart", | |
"spec": { | |
"visual": { | |
"lineWidth": 1.25, | |
"areaOpacity": 0.3, | |
"pointRadius": 2.75, | |
"connectNulls": false, | |
"display": "bar", | |
"stack": "all" | |
} | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_cost_usage{user_email=\"$user\"}[4h])) by (session_id)", | |
"seriesNameFormat": "{{session_id}}", | |
"minStep": "4h" | |
} | |
} | |
} | |
} | |
] | |
} | |
}, | |
"Cost/Session-1": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Token Usage per Session (Input & Output)" | |
}, | |
"plugin": { | |
"kind": "BarChart", | |
"spec": { | |
"calculation": "last", | |
"format": { | |
"unit": "decimal", | |
"shortValues": true | |
}, | |
"sort": "desc", | |
"mode": "value" | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_token_usage{user_email=\"$user\", model!~\".*haiku.*\"}[30d])) by (session_id)", | |
"seriesNameFormat": "{{session_id}}", | |
"minStep": "" | |
} | |
} | |
} | |
} | |
] | |
} | |
}, | |
"Cost/Session-2": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Lines of Code per Session" | |
}, | |
"plugin": { | |
"kind": "BarChart", | |
"spec": { | |
"calculation": "last", | |
"format": { | |
"unit": "decimal", | |
"shortValues": true | |
}, | |
"sort": "desc", | |
"mode": "value" | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_lines_of_code_count{user_email=\"$user\"}[30d])) by (session_id)", | |
"seriesNameFormat": "{{session_id}}", | |
"minStep": "" | |
} | |
} | |
} | |
} | |
] | |
} | |
}, | |
"Cost/Session-3": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Cost per Session" | |
}, | |
"plugin": { | |
"kind": "BarChart", | |
"spec": { | |
"calculation": "last", | |
"format": { | |
"unit": "decimal", | |
"shortValues": true | |
}, | |
"sort": "desc", | |
"mode": "value" | |
} | |
}, | |
"queries": [ | |
{ | |
"kind": "TimeSeriesQuery", | |
"spec": { | |
"plugin": { | |
"kind": "PrometheusTimeSeriesQuery", | |
"spec": { | |
"query": "sum(sum_over_time(claude_code_cost_usage{user_email=\"$user\"}[30d])) by (session_id)", | |
"seriesNameFormat": "{{session_id}}", | |
"minStep": "" | |
} | |
} | |
} | |
} | |
] | |
} | |
}, | |
"intro": { | |
"kind": "Panel", | |
"spec": { | |
"display": { | |
"name": "Intro" | |
}, | |
"plugin": { | |
"kind": "Markdown", | |
"spec": { | |
"text": "# Claude Code Stats\n\nThis dashboard is built with Claude Code's built-in **OpenTelemetry** observability data, using **GreptimeDB** as receiver. For more information, see [Monitoring from Anthropic docs](https://docs.anthropic.com/en/docs/claude-code/monitoring-usage)." | |
} | |
}, | |
"queries": [] | |
} | |
} | |
}, | |
"layouts": [ | |
{ | |
"kind": "Grid", | |
"spec": { | |
"display": { | |
"title": "Personal Overview (default 24 Hours)", | |
"collapse": { | |
"open": true | |
} | |
}, | |
"items": [ | |
{ | |
"x": 0, | |
"y": 9, | |
"width": 24, | |
"height": 5, | |
"content": { | |
"$ref": "#/spec/panels/lines_of_code_today" | |
} | |
}, | |
{ | |
"x": 0, | |
"y": 4, | |
"width": 12, | |
"height": 5, | |
"content": { | |
"$ref": "#/spec/panels/my_cost_today" | |
} | |
}, | |
{ | |
"x": 12, | |
"y": 4, | |
"width": 12, | |
"height": 5, | |
"content": { | |
"$ref": "#/spec/panels/tokens_used_today" | |
} | |
}, | |
{ | |
"x": 12, | |
"y": 14, | |
"width": 12, | |
"height": 4, | |
"content": { | |
"$ref": "#/spec/panels/code_efficiency" | |
} | |
}, | |
{ | |
"x": 0, | |
"y": 14, | |
"width": 12, | |
"height": 4, | |
"content": { | |
"$ref": "#/spec/panels/SessionCounterofToday" | |
} | |
}, | |
{ | |
"x": 0, | |
"y": 0, | |
"width": 24, | |
"height": 4, | |
"content": { | |
"$ref": "#/spec/panels/intro" | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"kind": "Grid", | |
"spec": { | |
"display": { | |
"title": "Coding Productivity", | |
"collapse": { | |
"open": true | |
} | |
}, | |
"items": [ | |
{ | |
"x": 0, | |
"y": 0, | |
"width": 24, | |
"height": 8, | |
"content": { | |
"$ref": "#/spec/panels/lines_of_code_trend" | |
} | |
}, | |
{ | |
"x": 0, | |
"y": 8, | |
"width": 24, | |
"height": 8, | |
"content": { | |
"$ref": "#/spec/panels/lines_of_code_trend-1" | |
} | |
}, | |
{ | |
"x": 0, | |
"y": 16, | |
"width": 24, | |
"height": 6, | |
"content": { | |
"$ref": "#/spec/panels/hourly_code_output" | |
} | |
}, | |
{ | |
"x": 0, | |
"y": 22, | |
"width": 24, | |
"height": 6, | |
"content": { | |
"$ref": "#/spec/panels/hourly_code_output-1" | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"kind": "Grid", | |
"spec": { | |
"display": { | |
"title": "Usage Patterns", | |
"collapse": { | |
"open": true | |
} | |
}, | |
"items": [ | |
{ | |
"x": 0, | |
"y": 0, | |
"width": 24, | |
"height": 8, | |
"content": { | |
"$ref": "#/spec/panels/cost_per_100_lines-1" | |
} | |
}, | |
{ | |
"x": 0, | |
"y": 8, | |
"width": 24, | |
"height": 8, | |
"content": { | |
"$ref": "#/spec/panels/cost_per_100_lines-3" | |
} | |
}, | |
{ | |
"x": 0, | |
"y": 16, | |
"width": 24, | |
"height": 6, | |
"content": { | |
"$ref": "#/spec/panels/cost_per_100_lines" | |
} | |
}, | |
{ | |
"x": 0, | |
"y": 22, | |
"width": 24, | |
"height": 6, | |
"content": { | |
"$ref": "#/spec/panels/cost_per_100_lines-4" | |
} | |
}, | |
{ | |
"x": 0, | |
"y": 28, | |
"width": 24, | |
"height": 6, | |
"content": { | |
"$ref": "#/spec/panels/cost_per_100_lines-5" | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"kind": "Grid", | |
"spec": { | |
"display": { | |
"title": "Session Usage", | |
"collapse": { | |
"open": true | |
} | |
}, | |
"items": [ | |
{ | |
"x": 0, | |
"y": 0, | |
"width": 24, | |
"height": 7, | |
"content": { | |
"$ref": "#/spec/panels/Cost/Session" | |
} | |
}, | |
{ | |
"x": 0, | |
"y": 7, | |
"width": 24, | |
"height": 6, | |
"content": { | |
"$ref": "#/spec/panels/Cost/Session-3" | |
} | |
}, | |
{ | |
"x": 0, | |
"y": 13, | |
"width": 24, | |
"height": 6, | |
"content": { | |
"$ref": "#/spec/panels/Cost/Session-1" | |
} | |
}, | |
{ | |
"x": 0, | |
"y": 19, | |
"width": 24, | |
"height": 6, | |
"content": { | |
"$ref": "#/spec/panels/Cost/Session-2" | |
} | |
} | |
] | |
} | |
} | |
], | |
"variables": [ | |
{ | |
"kind": "TextVariable", | |
"spec": { | |
"name": "user", | |
"display": { | |
"name": "User Email", | |
"description": "Your email address" | |
}, | |
"value": ".*", | |
"constant": false | |
} | |
}, | |
{ | |
"kind": "TextVariable", | |
"spec": { | |
"name": "model", | |
"display": { | |
"name": "Model", | |
"description": "Filter by model type" | |
}, | |
"value": ".*" | |
} | |
}, | |
{ | |
"kind": "TextVariable", | |
"spec": { | |
"name": "timerange", | |
"display": { | |
"name": "Time Range", | |
"description": "Time window for OverView queries(e.g., 24h, 7d, 30d)" | |
}, | |
"value": "4h" | |
} | |
} | |
], | |
"duration": "7d", | |
"refreshInterval": "30s", | |
"datasources": {} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment