From ff97503367252179b7f9e44be9bbfb5b1e2f8427 Mon Sep 17 00:00:00 2001 From: iris Date: Sun, 13 Sep 2026 16:32:31 +0200 Subject: [PATCH] swarm-grafana: add cost/tokens-by-agent panels to the claude usage dashboard The dashboard already templated an $agent variable and broke turns and active-time out by agent, but cost and token totals only split by model, effort and query_source -- there was no panel answering "how much did each agent spend/use", the aggregate-by-agent view mara asked for. --- .../dashboards/claude-usage.json | 120 +++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-) diff --git a/nix/host-modules/swarm-grafana/dashboards/claude-usage.json b/nix/host-modules/swarm-grafana/dashboards/claude-usage.json index a6e713fc..b76b9328 100644 --- a/nix/host-modules/swarm-grafana/dashboards/claude-usage.json +++ b/nix/host-modules/swarm-grafana/dashboards/claude-usage.json @@ -5,7 +5,7 @@ "tags": ["hyperhive", "claude"], "timezone": "utc", "schemaVersion": 39, - "version": 1, + "version": 2, "editable": true, "refresh": "1m", "time": { @@ -874,6 +874,124 @@ "values": false } } + }, + { + "id": 42, + "type": "bargauge", + "title": "Cost by agent", + "description": "claude_code.cost.usage summed over the selected range, broken out by agent — which agent the spend belongs to, as opposed to the model/effort/source breakdowns above.", + "datasource": { + "type": "prometheus", + "uid": "@datasourceUid@" + }, + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 32 + }, + "targets": [ + { + "refId": "A", + "datasource": { + "type": "prometheus", + "uid": "@datasourceUid@" + }, + "expr": "sum by (agent) (increase({__name__=\"claude_code.cost.usage\", hive=~\"$hive\", agent=~\"$agent\"}[$__range]))", + "instant": true, + "legendFormat": "{{agent}}" + } + ], + "fieldConfig": { + "defaults": { + "unit": "currencyUSD", + "decimals": 2, + "color": { + "mode": "fixed", + "fixedColor": "purple" + }, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "purple", + "value": null + } + ] + } + }, + "overrides": [] + }, + "options": { + "displayMode": "basic", + "orientation": "horizontal", + "showUnfilled": true, + "valueMode": "text", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + } + } + }, + { + "id": 43, + "type": "bargauge", + "title": "Tokens by agent", + "description": "claude_code.token.usage summed over the selected range, broken out by agent (all token types combined).", + "datasource": { + "type": "prometheus", + "uid": "@datasourceUid@" + }, + "gridPos": { + "h": 7, + "w": 12, + "x": 12, + "y": 32 + }, + "targets": [ + { + "refId": "A", + "datasource": { + "type": "prometheus", + "uid": "@datasourceUid@" + }, + "expr": "sum by (agent) (increase({__name__=\"claude_code.token.usage\", hive=~\"$hive\", agent=~\"$agent\"}[$__range]))", + "instant": true, + "legendFormat": "{{agent}}" + } + ], + "fieldConfig": { + "defaults": { + "unit": "short", + "decimals": 0, + "color": { + "mode": "fixed", + "fixedColor": "blue" + }, + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "blue", + "value": null + } + ] + } + }, + "overrides": [] + }, + "options": { + "displayMode": "basic", + "orientation": "horizontal", + "showUnfilled": true, + "valueMode": "text", + "reduceOptions": { + "calcs": ["lastNotNull"], + "fields": "", + "values": false + } + } } ] }