Skip to content

Instantly share code, notes, and snippets.

@miticojo
Created June 10, 2026 21:38
Show Gist options
  • Select an option

  • Save miticojo/0b348d54177399f53688fdb51d48f63b to your computer and use it in GitHub Desktop.

Select an option

Save miticojo/0b348d54177399f53688fdb51d48f63b to your computer and use it in GitHub Desktop.
{
"displayName": "Claude Code — daily cost per user over threshold",
"documentation": {
"content": "A user's Claude Code spend over the last 24h exceeded the configured threshold (default $50). Check the 'Cost Governance & Usage' dashboard, filter by the user in the incident labels, and review cost by model / query_source.",
"mimeType": "text/markdown"
},
"combiner": "OR",
"conditions": [
{
"displayName": "Cost per user over 24h > $50 (USD, Claude estimate)",
"conditionPrometheusQueryLanguage": {
"query": "sum by (user_email_gcp) (increase({__name__=\"claude_code.cost.usage\"}[1d])) > 50",
"duration": "0s",
"evaluationInterval": "300s",
"alertRule": "",
"ruleGroup": ""
}
}
],
"alertStrategy": {
"autoClose": "604800s"
},
"notificationChannels": [],
"enabled": true
}
{
"displayName": "Claude Code — Cost Governance & Usage",
"dashboardFilters": [
{ "filterType": "METRIC_LABEL", "labelKey": "user_email_gcp", "templateVariable": "", "stringValue": "" },
{ "filterType": "METRIC_LABEL", "labelKey": "model", "templateVariable": "", "stringValue": "" }
],
"mosaicLayout": {
"columns": 12,
"tiles": [
{
"xPos": 0, "yPos": 0, "width": 3, "height": 3,
"widget": {
"title": "Total cost (USD, Claude estimate)",
"scorecard": {
"timeSeriesQuery": {
"prometheusQuery": "sum(increase({__name__=\"claude_code.cost.usage\"}[${__interval}]))"
}
}
}
},
{
"xPos": 3, "yPos": 0, "width": 3, "height": 3,
"widget": {
"title": "Total tokens",
"scorecard": {
"timeSeriesQuery": {
"prometheusQuery": "sum(increase({__name__=\"claude_code.token.usage\"}[${__interval}]))"
}
}
}
},
{
"xPos": 6, "yPos": 0, "width": 3, "height": 3,
"widget": {
"title": "Active users",
"scorecard": {
"timeSeriesQuery": {
"prometheusQuery": "count(count by (user_email_gcp) (increase({__name__=\"claude_code.session.count\"}[${__interval}])))"
}
}
}
},
{
"xPos": 9, "yPos": 0, "width": 3, "height": 3,
"widget": {
"title": "Sessions",
"scorecard": {
"timeSeriesQuery": {
"prometheusQuery": "sum(increase({__name__=\"claude_code.session.count\"}[${__interval}]))"
}
}
}
},
{
"xPos": 0, "yPos": 3, "width": 6, "height": 4,
"widget": {
"title": "Cost over time by MODEL (USD/h)",
"xyChart": {
"dataSets": [
{
"plotType": "STACKED_AREA",
"targetAxis": "Y1",
"legendTemplate": "${model}",
"timeSeriesQuery": {
"prometheusQuery": "sum by (model) (rate({__name__=\"claude_code.cost.usage\"}[5m])) * 3600"
}
}
],
"yAxis": { "label": "USD/h", "scale": "LINEAR" }
}
}
},
{
"xPos": 6, "yPos": 3, "width": 6, "height": 4,
"widget": {
"title": "Cost over time by USER (USD/h)",
"xyChart": {
"dataSets": [
{
"plotType": "STACKED_AREA",
"targetAxis": "Y1",
"legendTemplate": "${user_email_gcp}",
"timeSeriesQuery": {
"prometheusQuery": "sum by (user_email_gcp) (rate({__name__=\"claude_code.cost.usage\"}[5m])) * 3600"
}
}
],
"yAxis": { "label": "USD/h", "scale": "LINEAR" }
}
}
},
{
"xPos": 0, "yPos": 7, "width": 12, "height": 5,
"widget": {
"title": "Usage per USER: input · output · cacheRead · cost (selected period)",
"timeSeriesTable": {
"dataSets": [
{
"tableTemplate": "input",
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"prometheus.googleapis.com/claude_code.token.usage/counter\" resource.type=\"prometheus_target\" metric.label.\"type\"=\"input\"",
"aggregation": {
"perSeriesAligner": "ALIGN_DELTA",
"crossSeriesReducer": "REDUCE_SUM",
"groupByFields": ["metric.label.user_email_gcp"],
"alignmentPeriod": "60s"
}
},
"outputFullDuration": true
}
},
{
"tableTemplate": "output",
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"prometheus.googleapis.com/claude_code.token.usage/counter\" resource.type=\"prometheus_target\" metric.label.\"type\"=\"output\"",
"aggregation": {
"perSeriesAligner": "ALIGN_DELTA",
"crossSeriesReducer": "REDUCE_SUM",
"groupByFields": ["metric.label.user_email_gcp"],
"alignmentPeriod": "60s"
}
},
"outputFullDuration": true
}
},
{
"tableTemplate": "cacheRead",
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"prometheus.googleapis.com/claude_code.token.usage/counter\" resource.type=\"prometheus_target\" metric.label.\"type\"=\"cacheRead\"",
"aggregation": {
"perSeriesAligner": "ALIGN_DELTA",
"crossSeriesReducer": "REDUCE_SUM",
"groupByFields": ["metric.label.user_email_gcp"],
"alignmentPeriod": "60s"
}
},
"outputFullDuration": true
}
},
{
"tableTemplate": "cost (USD)",
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"prometheus.googleapis.com/claude_code.cost.usage/counter\" resource.type=\"prometheus_target\"",
"aggregation": {
"perSeriesAligner": "ALIGN_DELTA",
"crossSeriesReducer": "REDUCE_SUM",
"groupByFields": ["metric.label.user_email_gcp"],
"alignmentPeriod": "60s"
}
},
"outputFullDuration": true
}
}
],
"metricVisualization": "NUMBER",
"columnSettings": [
{ "column": "user_email_gcp", "visible": true },
{ "column": "instance", "visible": false },
{ "column": "job", "visible": false },
{ "column": "namespace", "visible": false },
{ "column": "location", "visible": false },
{ "column": "project_id", "visible": false },
{ "column": "cluster", "visible": false }
]
}
}
},
{
"xPos": 0, "yPos": 12, "width": 6, "height": 5,
"widget": {
"title": "Cost by MODEL (selected period)",
"timeSeriesTable": {
"dataSets": [
{
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"prometheus.googleapis.com/claude_code.cost.usage/counter\" resource.type=\"prometheus_target\"",
"aggregation": {
"perSeriesAligner": "ALIGN_DELTA",
"crossSeriesReducer": "REDUCE_SUM",
"groupByFields": ["metric.label.model"],
"alignmentPeriod": "60s"
}
},
"outputFullDuration": true
}
}
],
"metricVisualization": "NUMBER"
}
}
},
{
"xPos": 6, "yPos": 12, "width": 6, "height": 5,
"widget": {
"title": "Tokens by MODEL and TYPE (selected period)",
"timeSeriesTable": {
"dataSets": [
{
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"prometheus.googleapis.com/claude_code.token.usage/counter\" resource.type=\"prometheus_target\"",
"aggregation": {
"perSeriesAligner": "ALIGN_DELTA",
"crossSeriesReducer": "REDUCE_SUM",
"groupByFields": ["metric.label.model", "metric.label.type"],
"alignmentPeriod": "60s"
}
},
"outputFullDuration": true
}
}
],
"metricVisualization": "NUMBER"
}
}
},
{
"xPos": 0, "yPos": 17, "width": 6, "height": 4,
"widget": {
"title": "Tokens over time by TYPE (tokens/s)",
"xyChart": {
"dataSets": [
{
"plotType": "STACKED_AREA",
"targetAxis": "Y1",
"legendTemplate": "${type}",
"timeSeriesQuery": {
"prometheusQuery": "sum by (type) (rate({__name__=\"claude_code.token.usage\"}[5m]))"
}
}
],
"yAxis": { "label": "tokens/s", "scale": "LINEAR" }
}
}
},
{
"xPos": 6, "yPos": 17, "width": 6, "height": 4,
"widget": {
"title": "Cache hit ratio by user (cacheRead / total tokens)",
"xyChart": {
"dataSets": [
{
"plotType": "LINE",
"targetAxis": "Y1",
"legendTemplate": "${user_email_gcp}",
"timeSeriesQuery": {
"prometheusQuery": "sum by (user_email_gcp) (rate({__name__=\"claude_code.token.usage\", type=\"cacheRead\"}[5m])) / sum by (user_email_gcp) (rate({__name__=\"claude_code.token.usage\"}[5m]))"
}
}
],
"yAxis": { "label": "ratio (0-1)", "scale": "LINEAR" }
}
}
},
{
"xPos": 0, "yPos": 21, "width": 6, "height": 4,
"widget": {
"title": "Cost by query_source (main vs subagent)",
"timeSeriesTable": {
"dataSets": [
{
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"prometheus.googleapis.com/claude_code.cost.usage/counter\" resource.type=\"prometheus_target\"",
"aggregation": {
"perSeriesAligner": "ALIGN_DELTA",
"crossSeriesReducer": "REDUCE_SUM",
"groupByFields": ["metric.label.query_source"],
"alignmentPeriod": "60s"
}
},
"outputFullDuration": true
}
}
],
"metricVisualization": "NUMBER"
}
}
},
{
"xPos": 6, "yPos": 21, "width": 6, "height": 4,
"widget": {
"title": "Cost by effort level",
"timeSeriesTable": {
"dataSets": [
{
"timeSeriesQuery": {
"timeSeriesFilter": {
"filter": "metric.type=\"prometheus.googleapis.com/claude_code.cost.usage/counter\" resource.type=\"prometheus_target\"",
"aggregation": {
"perSeriesAligner": "ALIGN_DELTA",
"crossSeriesReducer": "REDUCE_SUM",
"groupByFields": ["metric.label.effort"],
"alignmentPeriod": "60s"
}
},
"outputFullDuration": true
}
}
],
"metricVisualization": "NUMBER"
}
}
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment