swarm-grafana: replace busiest-agents bargauges with an actual table

mara: 'i asked for a table. ask when doing something different.' Right
call — the PR body flagged the bargauge substitution as an open question,
not a decision, and I should have waited for an answer instead of
treating the silent absence of an objection as one.

Single 'Busiest agents' table panel (replaces the 5 per-metric bargauges):
5 table-format instant queries (turns, input, output, cache-read, cost)
joined on the agent label (joinByField), renamed to the screenshot's own
column names via organize, sorted by turns descending via sortBy — same
column set and sort order as the attached /stats screenshot.

This is a genuinely novel schema shape for this repo: no table panel,
transformation, or field-override config exists anywhere else in
nix/host-modules/swarm-grafana/dashboards/*.json to verify the join/
organize/sortBy option shapes against. Structurally verified (valid
JSON, jq empty, unique panel ids, every panel referenced exactly once,
nix fmt clean, dashboard-description lint clean) but the join/rename
field-name mechanics (whether Grafana names the joined columns exactly
'Value #A'/'Value #B'/etc.) are built from general Grafana schema
knowledge, not a working local precedent — flagging that explicitly so
the actual render gets checked before merge.
This commit is contained in:
iris 2026-09-20 23:40:21 +02:00
commit c9ba906284

View file

@ -1751,8 +1751,8 @@
"kind": "Panel",
"spec": {
"id": 60,
"title": "Turns by agent",
"description": "Agent turns in the selected range, busiest first.",
"title": "Busiest agents",
"description": "Per-agent turns, tokens and cost in the selected range, busiest first.",
"links": [],
"data": {
"kind": "QueryGroup",
@ -1769,359 +1769,208 @@
"name": "@datasourceUid@"
},
"spec": {
"expr": "sort_desc(sum by (agent) (increase({__name__=\"hyperhive.agent.turn.count\", hive=~\"$hive\", agent=~\"$agent\"}[$__range])))",
"expr": "sum by (agent) (increase({__name__=\"hyperhive.agent.turn.count\", hive=~\"$hive\", agent=~\"$agent\"}[$__range]))",
"instant": true,
"legendFormat": "{{agent}}"
"format": "table",
"legendFormat": "__auto"
}
},
"refId": "A",
"hidden": false
}
},
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "prometheus",
"version": "v0",
"datasource": {
"name": "@datasourceUid@"
},
"spec": {
"expr": "sum by (agent) (increase({__name__=\"claude_code.token.usage\", hive=~\"$hive\", agent=~\"$agent\", type=\"input\"}[$__range]))",
"instant": true,
"format": "table",
"legendFormat": "__auto"
}
},
"refId": "B",
"hidden": false
}
},
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "prometheus",
"version": "v0",
"datasource": {
"name": "@datasourceUid@"
},
"spec": {
"expr": "sum by (agent) (increase({__name__=\"claude_code.token.usage\", hive=~\"$hive\", agent=~\"$agent\", type=\"output\"}[$__range]))",
"instant": true,
"format": "table",
"legendFormat": "__auto"
}
},
"refId": "C",
"hidden": false
}
},
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "prometheus",
"version": "v0",
"datasource": {
"name": "@datasourceUid@"
},
"spec": {
"expr": "sum by (agent) (increase({__name__=\"claude_code.token.usage\", hive=~\"$hive\", agent=~\"$agent\", type=\"cacheRead\"}[$__range]))",
"instant": true,
"format": "table",
"legendFormat": "__auto"
}
},
"refId": "D",
"hidden": false
}
},
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "prometheus",
"version": "v0",
"datasource": {
"name": "@datasourceUid@"
},
"spec": {
"expr": "sum by (agent) (increase({__name__=\"claude_code.cost.usage\", hive=~\"$hive\", agent=~\"$agent\"}[$__range]))",
"instant": true,
"format": "table",
"legendFormat": "__auto"
}
},
"refId": "E",
"hidden": false
}
}
],
"transformations": [],
"queryOptions": {}
}
},
"vizConfig": {
"kind": "VizConfig",
"group": "bargauge",
"version": "",
"spec": {
"options": {
"displayMode": "basic",
"orientation": "horizontal",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
"transformations": [
{
"id": "joinByField",
"options": {
"byField": "agent",
"mode": "outer"
}
},
"showUnfilled": true,
"valueMode": "text"
},
"fieldConfig": {
"defaults": {
"unit": "short",
"decimals": 0,
"thresholds": {
"mode": "absolute",
"steps": [
{
"id": "organize",
"options": {
"excludeByName": {
"Time": true
},
"indexByName": {
"agent": 0,
"Value #A": 1,
"Value #B": 2,
"Value #C": 3,
"Value #D": 4,
"Value #E": 5
},
"renameByName": {
"Value #A": "turns",
"Value #B": "input",
"Value #C": "output",
"Value #D": "cache read",
"Value #E": "est cost"
}
}
},
{
"id": "sortBy",
"options": {
"fields": {},
"sort": [
{
"value": null,
"color": "blue"
"field": "turns",
"desc": true
}
]
},
"color": {
"mode": "fixed",
"fixedColor": "blue"
}
},
"overrides": []
}
}
}
}
},
"panel-61": {
"kind": "Panel",
"spec": {
"id": 61,
"title": "Cost by agent",
"description": "USD spent in the selected range, busiest first.",
"links": [],
"data": {
"kind": "QueryGroup",
"spec": {
"queries": [
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "prometheus",
"version": "v0",
"datasource": {
"name": "@datasourceUid@"
},
"spec": {
"expr": "sort_desc(sum by (agent) (increase({__name__=\"claude_code.cost.usage\", hive=~\"$hive\", agent=~\"$agent\"}[$__range])))",
"instant": true,
"legendFormat": "{{agent}}"
}
},
"refId": "A",
"hidden": false
}
}
],
"transformations": [],
"queryOptions": {}
}
},
"vizConfig": {
"kind": "VizConfig",
"group": "bargauge",
"group": "table",
"version": "",
"spec": {
"options": {
"displayMode": "basic",
"orientation": "horizontal",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
"showUnfilled": true,
"valueMode": "text"
},
"fieldConfig": {
"defaults": {
"unit": "currencyUSD",
"decimals": 2,
"thresholds": {
"mode": "absolute",
"steps": [
{
"value": null,
"color": "purple"
}
]
},
"color": {
"mode": "fixed",
"fixedColor": "purple"
}
},
"overrides": []
}
}
}
}
},
"panel-62": {
"kind": "Panel",
"spec": {
"id": 62,
"title": "Input tokens by agent",
"description": "Input tokens in the selected range, busiest first.",
"links": [],
"data": {
"kind": "QueryGroup",
"spec": {
"queries": [
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "prometheus",
"version": "v0",
"datasource": {
"name": "@datasourceUid@"
},
"spec": {
"expr": "sort_desc(sum by (agent) (increase({__name__=\"claude_code.token.usage\", hive=~\"$hive\", agent=~\"$agent\", type=\"input\"}[$__range])))",
"instant": true,
"legendFormat": "{{agent}}"
}
},
"refId": "A",
"hidden": false
}
"showHeader": true,
"cellHeight": "sm",
"footer": {
"show": false,
"reducer": ["sum"],
"countRows": false
}
],
"transformations": [],
"queryOptions": {}
}
},
"vizConfig": {
"kind": "VizConfig",
"group": "bargauge",
"version": "",
"spec": {
"options": {
"displayMode": "basic",
"orientation": "horizontal",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
"showUnfilled": true,
"valueMode": "text"
},
"fieldConfig": {
"defaults": {
"unit": "short",
"decimals": 1,
"thresholds": {
"mode": "absolute",
"steps": [
{
"value": null,
"color": "blue"
}
]
},
"color": {
"mode": "fixed",
"fixedColor": "blue"
}
},
"overrides": []
}
}
}
}
},
"panel-63": {
"kind": "Panel",
"spec": {
"id": 63,
"title": "Output tokens by agent",
"description": "Output tokens in the selected range, busiest first.",
"links": [],
"data": {
"kind": "QueryGroup",
"spec": {
"queries": [
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "prometheus",
"version": "v0",
"datasource": {
"name": "@datasourceUid@"
},
"spec": {
"expr": "sort_desc(sum by (agent) (increase({__name__=\"claude_code.token.usage\", hive=~\"$hive\", agent=~\"$agent\", type=\"output\"}[$__range])))",
"instant": true,
"legendFormat": "{{agent}}"
}
"custom": {
"align": "auto",
"cellOptions": {
"type": "auto"
},
"refId": "A",
"hidden": false
}
}
],
"transformations": [],
"queryOptions": {}
}
},
"vizConfig": {
"kind": "VizConfig",
"group": "bargauge",
"version": "",
"spec": {
"options": {
"displayMode": "basic",
"orientation": "horizontal",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
"showUnfilled": true,
"valueMode": "text"
},
"fieldConfig": {
"defaults": {
"unit": "short",
"decimals": 1,
"thresholds": {
"mode": "absolute",
"steps": [
{
"value": null,
"color": "blue"
}
]
},
"color": {
"mode": "fixed",
"fixedColor": "blue"
"inspect": false
}
},
"overrides": []
}
}
}
}
},
"panel-64": {
"kind": "Panel",
"spec": {
"id": 64,
"title": "Cache read tokens by agent",
"description": "Cache-read tokens in the selected range, busiest first.",
"links": [],
"data": {
"kind": "QueryGroup",
"spec": {
"queries": [
{
"kind": "PanelQuery",
"spec": {
"query": {
"kind": "DataQuery",
"group": "prometheus",
"version": "v0",
"datasource": {
"name": "@datasourceUid@"
},
"spec": {
"expr": "sort_desc(sum by (agent) (increase({__name__=\"claude_code.token.usage\", hive=~\"$hive\", agent=~\"$agent\", type=\"cacheRead\"}[$__range])))",
"instant": true,
"legendFormat": "{{agent}}"
}
"overrides": [
{
"matcher": {
"id": "byName",
"options": "turns"
},
"refId": "A",
"hidden": false
}
}
],
"transformations": [],
"queryOptions": {}
}
},
"vizConfig": {
"kind": "VizConfig",
"group": "bargauge",
"version": "",
"spec": {
"options": {
"displayMode": "basic",
"orientation": "horizontal",
"reduceOptions": {
"calcs": ["lastNotNull"],
"fields": "",
"values": false
},
"showUnfilled": true,
"valueMode": "text"
},
"fieldConfig": {
"defaults": {
"unit": "short",
"decimals": 1,
"thresholds": {
"mode": "absolute",
"steps": [
"properties": [
{
"value": null,
"color": "blue"
"id": "unit",
"value": "short"
},
{
"id": "decimals",
"value": 0
}
]
},
"color": {
"mode": "fixed",
"fixedColor": "blue"
{
"matcher": {
"id": "byName",
"options": "est cost"
},
"properties": [
{
"id": "unit",
"value": "currencyUSD"
},
{
"id": "decimals",
"value": 2
}
]
}
},
"overrides": []
]
}
}
}
@ -2211,7 +2060,7 @@
"x": 0,
"y": 15,
"width": 24,
"height": 8,
"height": 10,
"element": {
"kind": "ElementReference",
"name": "panel-60"
@ -2321,58 +2170,6 @@
"name": "panel-55"
}
}
},
{
"kind": "GridLayoutItem",
"spec": {
"x": 0,
"y": 16,
"width": 12,
"height": 7,
"element": {
"kind": "ElementReference",
"name": "panel-61"
}
}
},
{
"kind": "GridLayoutItem",
"spec": {
"x": 12,
"y": 16,
"width": 12,
"height": 7,
"element": {
"kind": "ElementReference",
"name": "panel-62"
}
}
},
{
"kind": "GridLayoutItem",
"spec": {
"x": 0,
"y": 23,
"width": 12,
"height": 7,
"element": {
"kind": "ElementReference",
"name": "panel-63"
}
}
},
{
"kind": "GridLayoutItem",
"spec": {
"x": 12,
"y": 23,
"width": 12,
"height": 7,
"element": {
"kind": "ElementReference",
"name": "panel-64"
}
}
}
]
}