Skip to content

Commit c464fb4

Browse files
jwfingclaude
andcommitted
insta usage: show the 5 billing dimensions, not raw provider meters
Render the customer-facing dimensions (cpu/memory/volume/egress/storage) the platform now returns, with ram labelled 'memory'. Follows the platform /projects/:id/usage change to a { dimensions, totalCostUsd } response. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2305e97 commit c464fb4

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

src/commands/metrics.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,24 @@ export async function metrics(component: string, group: string | undefined, opts
2222
}
2323
}
2424

25-
// insta usage — aggregated usage by meter over a window
25+
// Customer-facing name for each internal billing dimension (the platform stores RAM as `ram`).
26+
const DIMENSION_LABEL: Record<string, string> = { ram: 'memory' }
27+
28+
// insta usage — usage across the 5 billing dimensions (cpu/memory/volume/egress/storage) we charge
29+
// on, over a window. Shows the billed dimensions, not the raw provider (fly/neon) meters.
2630
export async function usage(opts: { from?: string; to?: string; json?: boolean }): Promise<void> {
2731
const api = await ApiClient.load()
2832
const p = await requireProject()
2933
const res = await api.request('GET', `/projects/${p.projectId}/usage${qs({ from: opts.from, to: opts.to })}`)
3034
if (opts.json) return printJson(res)
3135
info(`usage ${new Date(res.from * 1000).toISOString().slice(0, 10)}${new Date(res.to * 1000).toISOString().slice(0, 10)}`)
32-
if (!res.usage?.length) return info('(no usage recorded)')
33-
let total = 0
34-
for (const u of res.usage) {
35-
const dims = u.dimensions && Object.keys(u.dimensions).length ? ` ${JSON.stringify(u.dimensions)}` : ''
36-
const cost = u.costUsd != null ? ` ($${Number(u.costUsd).toFixed(4)})` : ''
37-
total += Number(u.costUsd ?? 0)
38-
info(`${u.meter}${dims}: ${u.quantity} ${u.unit}${cost}`)
36+
if (!res.dimensions?.length) return info('(no usage recorded)')
37+
for (const d of res.dimensions) {
38+
const label = DIMENSION_LABEL[d.dimension] ?? d.dimension
39+
const cost = d.costUsd != null ? ` ($${Number(d.costUsd).toFixed(4)})` : ''
40+
info(`${label}: ${d.quantity} ${d.unit}${cost}`)
3941
}
40-
info(`total: $${total.toFixed(4)}`)
42+
info(`total: $${Number(res.totalCostUsd ?? 0).toFixed(4)}`)
4143
}
4244

4345
// insta logs <db|compute> [group]

0 commit comments

Comments
 (0)