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.
This commit is contained in:
iris 2026-09-13 16:32:31 +02:00 committed by mara
commit ff97503367

View file

@ -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
}
}
}
]
}