-
-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathai-usage.json
More file actions
485 lines (485 loc) · 34.3 KB
/
Copy pathai-usage.json
File metadata and controls
485 lines (485 loc) · 34.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
{
"uid": "loopover-ai-usage",
"title": "LoopOver - AI usage",
"tags": ["loopover", "ai"],
"timezone": "browser",
"schemaVersion": 39,
"version": 1,
"refresh": "30s",
"time": { "from": "now-7d", "to": "now" },
"description": "Consolidated AI-usage dashboard (replaces the old Claude/Codex/ORB AI-usage dashboards, and the AI-cost/token panels formerly in the infra dashboard). Two structurally different sources, kept in clearly separate sections: (1) the durable, cross-provider ai_usage_events log (migration 0109) — every configured provider (Ollama, Claude Code, Codex, OpenAI-compatible, Anthropic BYOK) and every AI feature (ai_review_pr, ai_slop_pr, embeddings, visual_vision, screenshot_table_vision, agent_private_summary, agent_public_summary, pr_intelligence_comment, linked_issue_satisfaction, issue_plan, unlinked_issue_verify, chat_qa, intent_routing, ai_key_change), filterable by $provider/$feature/$model and repo/PR-attributable; (2) Claude Code's own OTEL session telemetry, a separate non-durable data source with no repo/PR attribution that cannot be joined to (1) — kept in its own section rather than force-merged. A row of live Prometheus counters sits between them for real-time signal the durable log can lag behind (it's written after a call completes).",
"templating": {
"list": [
{
"name": "provider",
"label": "Provider",
"type": "query",
"datasource": { "type": "frser-sqlite-datasource", "uid": "loopover-db" },
"query": { "refId": "A", "queryType": "table", "queryText": "SELECT DISTINCT provider FROM ai_usage_events WHERE provider IS NOT NULL ORDER BY provider", "rawQueryText": "SELECT DISTINCT provider FROM ai_usage_events WHERE provider IS NOT NULL ORDER BY provider" },
"includeAll": true,
"allValue": "__ALL__",
"multi": false,
"current": { "text": "All", "value": "__ALL__" },
"refresh": 2,
"sort": 1
},
{
"name": "feature",
"label": "Feature",
"type": "query",
"datasource": { "type": "frser-sqlite-datasource", "uid": "loopover-db" },
"query": { "refId": "A", "queryType": "table", "queryText": "SELECT DISTINCT feature FROM ai_usage_events ORDER BY feature", "rawQueryText": "SELECT DISTINCT feature FROM ai_usage_events ORDER BY feature" },
"includeAll": true,
"allValue": "__ALL__",
"multi": false,
"current": { "text": "All", "value": "__ALL__" },
"refresh": 2,
"sort": 1
},
{
"name": "model",
"label": "Model",
"type": "query",
"datasource": { "type": "frser-sqlite-datasource", "uid": "loopover-db" },
"query": {
"refId": "A",
"queryType": "table",
"queryText": "SELECT DISTINCT model FROM ai_usage_events WHERE (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) ORDER BY model",
"rawQueryText": "SELECT DISTINCT model FROM ai_usage_events WHERE (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) ORDER BY model"
},
"includeAll": true,
"allValue": "__ALL__",
"multi": false,
"current": { "text": "All", "value": "__ALL__" },
"refresh": 2,
"sort": 1,
"description": "Narrows to the selected Provider's own models (e.g. Ollama's separate bge-m3/qwen3-vl/qwen3 use cases)."
},
{
"name": "claudeModel",
"label": "Claude Model (OTEL)",
"type": "query",
"datasource": { "type": "prometheus", "uid": "prometheus" },
"definition": "label_values(claude_code_cost_usage_USD_total, model)",
"query": { "query": "label_values(claude_code_cost_usage_USD_total, model)", "refId": "A" },
"includeAll": true,
"multi": true,
"allValue": ".*",
"current": { "text": "All", "value": "__ALL__" },
"refresh": 2,
"description": "Only scopes the separate 'Claude Code native OTEL telemetry' section below — unrelated to Provider/Feature/Model above, which scope the durable ai_usage_events log."
}
]
},
"annotations": { "list": [] },
"links": [
{
"title": "Miner usage (AMS)",
"type": "link",
"url": "/d/loopover-miner-usage/loopover-miner-usage",
"icon": "external link",
"targetBlank": false,
"tooltip": "AMS's own coding-agent usage dashboard -- a separate local CLI (loopover-miner) from every provider above, tracked on its own dashboard since it's a structurally different local-SQLite source, not another row in ai_usage_events."
}
],
"panels": [
{
"id": 1,
"type": "row",
"title": "Summary (durable log, filtered)",
"gridPos": { "h": 1, "w": 24, "x": 0, "y": 0 }
},
{
"id": 2,
"type": "stat",
"title": "Total AI events",
"description": "Every ai_usage_events row with a non-null provider (i.e. a real, attributed AI call) in the selected time range, filtered by Provider/Feature/Model.",
"gridPos": { "h": 5, "w": 6, "x": 0, "y": 1 },
"datasource": { "type": "frser-sqlite-datasource", "uid": "loopover-db" },
"fieldConfig": { "defaults": { "unit": "short", "color": { "mode": "fixed", "fixedColor": "blue" } } },
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none", "justifyMode": "center" },
"targets": [
{
"refId": "A",
"queryType": "table",
"queryText": "SELECT count(*) AS events FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds}",
"rawQueryText": "SELECT count(*) AS events FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds}"
}
]
},
{
"id": 3,
"type": "stat",
"title": "Total tokens",
"gridPos": { "h": 5, "w": 6, "x": 6, "y": 1 },
"datasource": { "type": "frser-sqlite-datasource", "uid": "loopover-db" },
"fieldConfig": { "defaults": { "unit": "short", "color": { "mode": "fixed", "fixedColor": "purple" } } },
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none", "justifyMode": "center" },
"targets": [
{
"refId": "A",
"queryType": "table",
"queryText": "SELECT coalesce(sum(total_tokens), 0) AS total_tokens FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds}",
"rawQueryText": "SELECT coalesce(sum(total_tokens), 0) AS total_tokens FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds}"
}
]
},
{
"id": 4,
"type": "stat",
"title": "Total cost",
"gridPos": { "h": 5, "w": 6, "x": 12, "y": 1 },
"datasource": { "type": "frser-sqlite-datasource", "uid": "loopover-db" },
"fieldConfig": { "defaults": { "unit": "currencyUSD", "decimals": 4, "color": { "mode": "fixed", "fixedColor": "green" } } },
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none", "justifyMode": "center" },
"targets": [
{
"refId": "A",
"queryType": "table",
"queryText": "SELECT coalesce(sum(cost_usd), 0) AS cost_usd FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds}",
"rawQueryText": "SELECT coalesce(sum(cost_usd), 0) AS cost_usd FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds}"
}
]
},
{
"id": 5,
"type": "stat",
"title": "Events missing real usage",
"description": "Completed AI calls (status='ok') with no real usage captured (no provider attribution, or every numeric field still at its zero default). Only scoped by Feature + time range — not by Provider/Model, since a NULL provider is exactly the kind of row this panel exists to surface, and filtering it out by provider would hide the very rows it's meant to catch. Excludes quota_exceeded/disabled/unavailable (no call was attempted) and ai_key_change (not an AI call).",
"gridPos": { "h": 5, "w": 6, "x": 18, "y": 1 },
"datasource": { "type": "frser-sqlite-datasource", "uid": "loopover-db" },
"fieldConfig": { "defaults": { "unit": "short", "color": { "mode": "fixed", "fixedColor": "orange" } } },
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none", "justifyMode": "center" },
"targets": [
{
"refId": "A",
"queryType": "table",
"queryText": "SELECT count(*) AS unattributed FROM ai_usage_events WHERE status = 'ok' AND feature <> 'ai_key_change' AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (provider IS NULL OR (input_tokens = 0 AND output_tokens = 0 AND total_tokens = 0 AND cost_usd = 0)) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds}",
"rawQueryText": "SELECT count(*) AS unattributed FROM ai_usage_events WHERE status = 'ok' AND feature <> 'ai_key_change' AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (provider IS NULL OR (input_tokens = 0 AND output_tokens = 0 AND total_tokens = 0 AND cost_usd = 0)) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds}"
}
]
},
{
"id": 6,
"type": "row",
"title": "Usage by category (what's using the most, and is anything spiking)",
"gridPos": { "h": 1, "w": 24, "x": 0, "y": 6 }
},
{
"id": 7,
"type": "timeseries",
"title": "Tokens by feature, over time",
"description": "Stacked daily token totals per feature within the selected Provider/Model filter — a spike in one feature's stack is the signal to investigate.",
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 7 },
"datasource": { "type": "frser-sqlite-datasource", "uid": "loopover-db" },
"fieldConfig": { "defaults": { "unit": "short", "custom": { "drawStyle": "bars", "fillOpacity": 70, "lineWidth": 1, "stacking": { "mode": "normal" } } } },
"options": { "legend": { "showLegend": true, "placement": "bottom" }, "tooltip": { "mode": "multi", "sort": "desc" } },
"targets": [
{
"refId": "A",
"queryType": "time series",
"timeColumns": ["time"],
"metricColumn": "feature",
"queryText": "SELECT unixepoch(date(created_at)) * 1000 AS time, feature, coalesce(sum(total_tokens), 0) AS tokens FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds} GROUP BY date(created_at), feature ORDER BY time",
"rawQueryText": "SELECT unixepoch(date(created_at)) * 1000 AS time, feature, coalesce(sum(total_tokens), 0) AS tokens FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds} GROUP BY date(created_at), feature ORDER BY time"
}
]
},
{
"id": 8,
"type": "piechart",
"title": "Cost share by feature",
"gridPos": { "h": 8, "w": 6, "x": 12, "y": 7 },
"datasource": { "type": "frser-sqlite-datasource", "uid": "loopover-db" },
"fieldConfig": { "defaults": { "unit": "currencyUSD" } },
"options": { "pieType": "donut", "legend": { "showLegend": true, "placement": "right", "values": ["percent", "value"] }, "reduceOptions": { "calcs": ["lastNotNull"] }, "displayLabels": ["percent"] },
"targets": [
{
"refId": "A",
"queryType": "table",
"queryText": "SELECT feature, coalesce(sum(cost_usd), 0) AS cost_usd FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds} GROUP BY feature ORDER BY cost_usd DESC",
"rawQueryText": "SELECT feature, coalesce(sum(cost_usd), 0) AS cost_usd FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds} GROUP BY feature ORDER BY cost_usd DESC"
}
]
},
{
"id": 9,
"type": "piechart",
"title": "Events by provider",
"gridPos": { "h": 8, "w": 6, "x": 18, "y": 7 },
"datasource": { "type": "frser-sqlite-datasource", "uid": "loopover-db" },
"fieldConfig": { "defaults": { "unit": "short" } },
"options": { "pieType": "donut", "legend": { "showLegend": true, "placement": "right", "values": ["percent", "value"] }, "reduceOptions": { "calcs": ["lastNotNull"] }, "displayLabels": ["percent"] },
"targets": [
{
"refId": "A",
"queryType": "table",
"queryText": "SELECT provider, count(*) AS events FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds} GROUP BY provider ORDER BY events DESC",
"rawQueryText": "SELECT provider, count(*) AS events FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds} GROUP BY provider ORDER BY events DESC"
}
]
},
{
"id": 10,
"type": "table",
"title": "Usage by provider + model + effort",
"gridPos": { "h": 8, "w": 24, "x": 0, "y": 15 },
"datasource": { "type": "frser-sqlite-datasource", "uid": "loopover-db" },
"options": { "showHeader": true, "cellHeight": "sm", "sortBy": [{ "displayName": "events", "desc": true }] },
"fieldConfig": { "defaults": { "custom": { "filterable": true } } },
"targets": [
{
"refId": "A",
"queryType": "table",
"queryText": "SELECT provider, model, effort, count(*) AS events, coalesce(sum(total_tokens), 0) AS total_tokens, coalesce(sum(cost_usd), 0) AS cost_usd FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds} GROUP BY provider, model, effort ORDER BY events DESC LIMIT 50",
"rawQueryText": "SELECT provider, model, effort, count(*) AS events, coalesce(sum(total_tokens), 0) AS total_tokens, coalesce(sum(cost_usd), 0) AS cost_usd FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds} GROUP BY provider, model, effort ORDER BY events DESC LIMIT 50"
}
]
},
{
"id": 11,
"type": "row",
"title": "By repo / PR",
"gridPos": { "h": 1, "w": 24, "x": 0, "y": 23 }
},
{
"id": 12,
"type": "table",
"title": "Top repos by AI usage",
"gridPos": { "h": 10, "w": 12, "x": 0, "y": 24 },
"datasource": { "type": "frser-sqlite-datasource", "uid": "loopover-db" },
"options": { "showHeader": true, "cellHeight": "sm", "sortBy": [{ "displayName": "events", "desc": true }] },
"fieldConfig": { "defaults": { "custom": { "filterable": true } } },
"targets": [
{
"refId": "A",
"queryType": "table",
"queryText": "SELECT json_extract(metadata_json, '$.repoFullName') AS repo, provider, count(*) AS events, coalesce(sum(total_tokens), 0) AS total_tokens, coalesce(sum(cost_usd), 0) AS cost_usd FROM ai_usage_events WHERE provider IS NOT NULL AND json_extract(metadata_json, '$.repoFullName') IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds} GROUP BY repo, provider ORDER BY events DESC LIMIT 50",
"rawQueryText": "SELECT json_extract(metadata_json, '$.repoFullName') AS repo, provider, count(*) AS events, coalesce(sum(total_tokens), 0) AS total_tokens, coalesce(sum(cost_usd), 0) AS cost_usd FROM ai_usage_events WHERE provider IS NOT NULL AND json_extract(metadata_json, '$.repoFullName') IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds} GROUP BY repo, provider ORDER BY events DESC LIMIT 50"
}
]
},
{
"id": 13,
"type": "table",
"title": "Recent AI events",
"gridPos": { "h": 10, "w": 12, "x": 12, "y": 24 },
"datasource": { "type": "frser-sqlite-datasource", "uid": "loopover-db" },
"options": { "showHeader": true, "cellHeight": "sm", "sortBy": [{ "displayName": "created_at", "desc": true }] },
"fieldConfig": { "defaults": { "custom": { "filterable": true } } },
"targets": [
{
"refId": "A",
"queryType": "table",
"queryText": "SELECT created_at, feature, provider, model, effort, status, input_tokens, output_tokens, total_tokens, cost_usd, json_extract(metadata_json, '$.repoFullName') AS repo, json_extract(metadata_json, '$.pullNumber') AS pr FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds} ORDER BY created_at DESC LIMIT 100",
"rawQueryText": "SELECT created_at, feature, provider, model, effort, status, input_tokens, output_tokens, total_tokens, cost_usd, json_extract(metadata_json, '$.repoFullName') AS repo, json_extract(metadata_json, '$.pullNumber') AS pr FROM ai_usage_events WHERE provider IS NOT NULL AND (${provider:sqlstring} = '__ALL__' OR provider = ${provider:sqlstring}) AND (${feature:sqlstring} = '__ALL__' OR feature = ${feature:sqlstring}) AND (${model:sqlstring} = '__ALL__' OR model = ${model:sqlstring}) AND unixepoch(created_at) >= ${__from:date:seconds} AND unixepoch(created_at) < ${__to:date:seconds} ORDER BY created_at DESC LIMIT 100"
}
]
},
{
"id": 14,
"type": "row",
"title": "Live Prometheus counters (all providers, real-time — the durable log above is written after a call completes)",
"gridPos": { "h": 1, "w": 24, "x": 0, "y": 34 }
},
{
"id": 15,
"type": "timeseries",
"title": "Cumulative AI cost (USD) by provider",
"description": "loopover's own monotonic cost counter (loopover_ai_cost_usd_total) — continuously scraped, so it draws a clean cumulative line. Resets to 0 on a stack restart.",
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 35 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": { "defaults": { "unit": "currencyUSD", "color": { "mode": "palette-classic" }, "custom": { "lineWidth": 2, "fillOpacity": 10 } } },
"options": { "legend": { "showLegend": true, "placement": "bottom" }, "tooltip": { "mode": "multi" } },
"targets": [{ "refId": "A", "expr": "sum by (provider) ((loopover_ai_cost_usd_total or gittensory_ai_cost_usd_total)) or vector(0)", "legendFormat": "{{provider}}" }]
},
{
"id": 16,
"type": "timeseries",
"title": "Tokens/min by provider",
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 35 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": { "defaults": { "unit": "short", "color": { "mode": "palette-classic" }, "custom": { "lineWidth": 2, "fillOpacity": 10 } } },
"options": { "legend": { "showLegend": true, "placement": "bottom" }, "tooltip": { "mode": "multi" } },
"targets": [
{
"refId": "A",
"expr": "sum by (provider) (((rate(loopover_ai_input_tokens_total[5m]) or rate(gittensory_ai_input_tokens_total[5m])) + (rate(loopover_ai_output_tokens_total[5m]) or rate(gittensory_ai_output_tokens_total[5m]))) * 60)",
"legendFormat": "{{provider}}"
}
]
},
{
"id": 17,
"type": "timeseries",
"title": "AI requests + fallbacks (last 1h)",
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 43 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": { "defaults": { "unit": "short", "color": { "mode": "palette-classic" }, "custom": { "lineWidth": 2, "fillOpacity": 10 } } },
"options": { "legend": { "showLegend": true, "placement": "bottom" }, "tooltip": { "mode": "multi" } },
"targets": [
{ "refId": "A", "expr": "sum by (model, effort) ((increase(loopover_ai_requests_total[1h]) or increase(gittensory_ai_requests_total[1h])))", "legendFormat": "{{model}} · {{effort}}" },
{ "refId": "B", "expr": "sum by (primary, fallback) ((increase(loopover_ai_review_model_fallback_total[1h]) or increase(gittensory_ai_review_model_fallback_total[1h])))", "legendFormat": "fallback {{primary}}→{{fallback}}" }
]
},
{
"id": 18,
"type": "timeseries",
"title": "Total tokens by provider + kind",
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 43 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": { "defaults": { "unit": "short", "color": { "mode": "palette-classic" }, "custom": { "lineWidth": 2, "fillOpacity": 10 } } },
"options": { "legend": { "showLegend": true, "placement": "bottom" }, "tooltip": { "mode": "multi" } },
"targets": [
{ "refId": "A", "expr": "sum by (provider, kind) ((loopover_ai_input_tokens_total or gittensory_ai_input_tokens_total))", "legendFormat": "{{provider}} {{kind}} in" },
{ "refId": "B", "expr": "sum by (provider, kind) ((loopover_ai_output_tokens_total or gittensory_ai_output_tokens_total))", "legendFormat": "{{provider}} {{kind}} out" }
]
},
{
"id": 19,
"type": "timeseries",
"title": "Codex CLI attempts by model and effort",
"description": "Codex-specific: raw CLI attempt counters, including attempts that never produced a usable response (so never landed a durable ai_usage_events row).",
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 51 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": { "defaults": { "unit": "short", "custom": { "drawStyle": "bars", "fillOpacity": 70, "lineWidth": 1, "stacking": { "mode": "none" } } } },
"options": { "legend": { "showLegend": true, "placement": "bottom" }, "tooltip": { "mode": "multi", "sort": "desc" } },
"targets": [
{
"refId": "A",
"expr": "sum by (model, effort) ((increase(loopover_ai_requests_total{provider=\"codex\"}[$__rate_interval]) or increase(gittensory_ai_requests_total{provider=\"codex\"}[$__rate_interval])))",
"legendFormat": "{{model}} / {{effort}}"
}
]
},
{
"id": 20,
"type": "timeseries",
"title": "Codex reported tokens by direction",
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 51 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": { "defaults": { "unit": "short", "custom": { "drawStyle": "bars", "fillOpacity": 70, "lineWidth": 1, "stacking": { "mode": "normal" } } } },
"options": { "legend": { "showLegend": true, "placement": "bottom" }, "tooltip": { "mode": "multi", "sort": "desc" } },
"targets": [
{ "refId": "A", "expr": "sum by (kind) ((increase(loopover_ai_input_tokens_total{provider=\"codex\"}[$__rate_interval]) or increase(gittensory_ai_input_tokens_total{provider=\"codex\"}[$__rate_interval])))", "legendFormat": "input {{kind}}" },
{ "refId": "B", "expr": "sum by (kind) ((increase(loopover_ai_output_tokens_total{provider=\"codex\"}[$__rate_interval]) or increase(gittensory_ai_output_tokens_total{provider=\"codex\"}[$__rate_interval])))", "legendFormat": "output {{kind}}" }
]
},
{
"id": 21,
"type": "row",
"title": "Claude Code native OTEL telemetry (session-scoped CLI metrics — NOT joinable with the durable log above)",
"gridPos": { "h": 1, "w": 24, "x": 0, "y": 59 }
},
{
"id": 22,
"type": "stat",
"title": "Total cost",
"description": "Each headless review is a session-scoped cumulative counter, so totals use last_over_time (sum of each session's final value) — increase()/rate() would read flat because a session exports its total in one shot.",
"gridPos": { "h": 5, "w": 5, "x": 0, "y": 60 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": { "defaults": { "unit": "currencyUSD", "decimals": 2, "color": { "mode": "fixed", "fixedColor": "green" } } },
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "background_solid", "graphMode": "none", "justifyMode": "center" },
"targets": [{ "refId": "A", "instant": true, "expr": "sum(last_over_time(claude_code_cost_usage_USD_total{model=~\"$claudeModel\"}[$__range]))" }]
},
{
"id": 23,
"type": "stat",
"title": "Total tokens",
"gridPos": { "h": 5, "w": 5, "x": 5, "y": 60 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": { "defaults": { "unit": "short", "color": { "mode": "fixed", "fixedColor": "blue" } } },
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none", "justifyMode": "center" },
"targets": [{ "refId": "A", "instant": true, "expr": "sum(last_over_time(claude_code_token_usage_tokens_total{model=~\"$claudeModel\"}[$__range]))" }]
},
{
"id": 24,
"type": "stat",
"title": "Sessions",
"gridPos": { "h": 5, "w": 5, "x": 10, "y": 60 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": { "defaults": { "unit": "short", "color": { "mode": "fixed", "fixedColor": "purple" } } },
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none", "justifyMode": "center" },
"targets": [{ "refId": "A", "instant": true, "expr": "sum(last_over_time(claude_code_session_count_total[$__range]))" }]
},
{
"id": 25,
"type": "stat",
"title": "Active time",
"gridPos": { "h": 5, "w": 4, "x": 15, "y": 60 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": { "defaults": { "unit": "s", "color": { "mode": "fixed", "fixedColor": "orange" } } },
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none", "justifyMode": "center" },
"targets": [{ "refId": "A", "instant": true, "expr": "sum(last_over_time(claude_code_active_time_seconds_total[$__range]))" }]
},
{
"id": 26,
"type": "stat",
"title": "Lines of code",
"gridPos": { "h": 5, "w": 5, "x": 19, "y": 60 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": { "defaults": { "unit": "short", "color": { "mode": "fixed", "fixedColor": "yellow" } } },
"options": { "reduceOptions": { "calcs": ["lastNotNull"] }, "colorMode": "value", "graphMode": "none", "justifyMode": "center" },
"targets": [{ "refId": "A", "instant": true, "expr": "sum(last_over_time(claude_code_lines_of_code_count_total[$__range]))" }]
},
{
"id": 27,
"type": "timeseries",
"title": "Cost by model (per scrape interval)",
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 65 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": { "defaults": { "unit": "currencyUSD", "custom": { "drawStyle": "bars", "fillOpacity": 70, "lineWidth": 1, "gradientMode": "opacity" } } },
"options": { "legend": { "showLegend": true, "placement": "bottom", "displayMode": "table", "calcs": ["max"] }, "tooltip": { "mode": "multi", "sort": "desc" } },
"targets": [{ "refId": "A", "expr": "sum by (model) (last_over_time(claude_code_cost_usage_USD_total{model=~\"$claudeModel\"}[$__rate_interval]))", "legendFormat": "{{model}}" }]
},
{
"id": 28,
"type": "piechart",
"title": "Tokens by type",
"gridPos": { "h": 8, "w": 6, "x": 12, "y": 65 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": { "defaults": { "unit": "short" } },
"options": { "pieType": "donut", "legend": { "showLegend": true, "placement": "right", "values": ["percent", "value"] }, "reduceOptions": { "calcs": ["lastNotNull"] }, "displayLabels": ["percent"] },
"targets": [{ "refId": "A", "instant": true, "expr": "sum by (type) (last_over_time(claude_code_token_usage_tokens_total{model=~\"$claudeModel\"}[$__range]))", "legendFormat": "{{type}}" }]
},
{
"id": 29,
"type": "bargauge",
"title": "Cost by model",
"gridPos": { "h": 8, "w": 6, "x": 18, "y": 65 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": { "defaults": { "unit": "currencyUSD", "decimals": 4, "color": { "mode": "continuous-GrYlRd" } } },
"options": { "orientation": "horizontal", "displayMode": "gradient", "valueMode": "color", "reduceOptions": { "calcs": ["lastNotNull"] } },
"targets": [{ "refId": "A", "instant": true, "expr": "sum by (model) (last_over_time(claude_code_cost_usage_USD_total{model=~\"$claudeModel\"}[$__range]))", "legendFormat": "{{model}}" }]
},
{
"id": 30,
"type": "timeseries",
"title": "Tokens by type (per scrape interval)",
"gridPos": { "h": 8, "w": 12, "x": 0, "y": 73 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"fieldConfig": { "defaults": { "unit": "short", "custom": { "drawStyle": "bars", "fillOpacity": 80, "lineWidth": 0, "stacking": { "mode": "normal" } } } },
"options": { "legend": { "showLegend": true, "placement": "bottom" }, "tooltip": { "mode": "multi", "sort": "desc" } },
"targets": [{ "refId": "A", "expr": "sum by (type) (last_over_time(claude_code_token_usage_tokens_total{model=~\"$claudeModel\"}[$__rate_interval]))", "legendFormat": "{{type}}" }]
},
{
"id": 31,
"type": "table",
"title": "Cost by model × effort",
"gridPos": { "h": 8, "w": 12, "x": 12, "y": 73 },
"datasource": { "type": "prometheus", "uid": "prometheus" },
"options": { "showHeader": true, "cellHeight": "sm", "sortBy": [{ "displayName": "Cost", "desc": true }] },
"fieldConfig": {
"defaults": { "custom": { "filterable": true } },
"overrides": [
{
"matcher": { "id": "byName", "options": "Cost" },
"properties": [{ "id": "unit", "value": "currencyUSD" }, { "id": "decimals", "value": 4 }, { "id": "custom.cellOptions", "value": { "type": "gauge", "mode": "gradient" } }]
}
]
},
"targets": [{ "refId": "A", "format": "table", "instant": true, "expr": "sum by (model, effort) (last_over_time(claude_code_cost_usage_USD_total{model=~\"$claudeModel\"}[$__range]))" }],
"transformations": [{ "id": "organize", "options": { "renameByName": { "Value": "Cost" }, "excludeByName": { "Time": true } } }]
}
]
}