id: gpu-idle-cost-attribution
namespace: company.team
description: |
Attribute wasted GPU cost-hours to the teams that own idle accelerator
nodes before the monthly bill lands. A utilization exporter POSTs a node
inventory with owner tags to a keyed webhook, Python flags every GPU node
whose utilization and idle duration breach policy, a Loop walks the per
team attribution rows and alerts each owning team, and a final If escalates
the fleet-wide totals and fails the run when any idle node was found.
A fully consumed fleet is logged, and the idle nodes, attributed GPU-hours,
the dollar estimate and the full per team table are published as outputs.
triggers:
- id: on_utilization_publish
type: io.kestra.plugin.core.trigger.Webhook
description: The cluster utilization exporter POSTs the GPU node inventory with
owner tags here so attribution runs as soon as a sampling window closes.
key: "{{ secret('GPU_COST_WEBHOOK_KEY') }}"
- id: monthly_idle_attribution
type: io.kestra.plugin.core.trigger.Schedule
description: Monthly net on the first at 06:00 UTC that re-scores the last
inventory, shipped disabled until the webhook path is trusted in your
environment.
cron: "0 6 1 * *"
disabled: true
inputs:
- id: idle_utilization_threshold_pct
type: FLOAT
defaults: 5.0
description: GPU utilization percentage at or below which a node counts as idle
across the whole sampling window.
- id: min_idle_hours
type: INT
defaults: 6
description: Consecutive idle hours a node must accumulate before it is charged,
so short gaps between jobs never appear in the report.
- id: gpu_hourly_rate_usd
type: FLOAT
defaults: 2.4
description: Blended on-demand USD rate per GPU-hour used to convert idle hours
into the attributed cost estimate.
tasks:
# --- 1. attribution score ---
- id: attribute_idle
type: io.kestra.plugin.scripts.python.Script
description: Read the posted node inventory or the bundled example fleet, charge
every GPU node that breaches both the utilization and the idle duration
policy, roll the GPU-hours and dollars up per owning team, and emit the
fleet verdict through the outputs protocol.
containerImage: python:3.12-slim
env:
GPU_NODE_JSON: "{{ trigger.body ?? '' }}"
IDLE_UTIL_PCT: "{{ inputs.idle_utilization_threshold_pct }}"
MIN_IDLE_HOURS: "{{ inputs.min_idle_hours }}"
GPU_HOURLY_RATE_USD: "{{ inputs.gpu_hourly_rate_usd }}"
script: |
import json
import os
DEFAULT_INVENTORY = """
{
"billing_period": "2026-10",
"nodes": [
{"node": "gpu-node-a100-01", "team": "vision-platform", "region": "us-east-1", "gpus": 8, "gpu_util_pct": 1.2, "idle_hours": 72},
{"node": "gpu-node-a100-02", "team": "vision-platform", "region": "us-east-1", "gpus": 8, "gpu_util_pct": 61.4, "idle_hours": 72},
{"node": "gpu-node-l4-07", "team": "recommendations", "region": "us-west-2", "gpus": 4, "gpu_util_pct": 3.9, "idle_hours": 4},
{"node": "gpu-node-h100-03", "team": "training-infra", "region": "us-east-1", "gpus": 8, "gpu_util_pct": 0.4, "idle_hours": 96},
{"node": "gpu-node-t4-11", "team": "recommendations", "region": "eu-west-1", "gpus": 2, "gpu_util_pct": 12.5, "idle_hours": 30}
]
}
"""
def as_int(value, fallback=0):
try:
return int(value)
except (TypeError, ValueError):
try:
return int(float(value))
except (TypeError, ValueError):
return fallback
def as_float(value, fallback=0.0):
try:
return float(value)
except (TypeError, ValueError):
return fallback
raw = (os.environ.get("GPU_NODE_JSON") or "").strip() or DEFAULT_INVENTORY.strip()
threshold = as_float(os.environ.get("IDLE_UTIL_PCT"), 5.0)
min_idle = as_float(os.environ.get("MIN_IDLE_HOURS"), 6)
rate = as_float(os.environ.get("GPU_HOURLY_RATE_USD"), 2.4)
outputs = {
"scan_ok": False,
"billing_period": "unknown",
"nodes_scanned": 0,
"idle_node_count": 0,
"idle_nodes": [],
"attributed_hours": 0.0,
"attributed_cost_usd": 0.0,
"team_attribution": [],
"worst_team": "none",
}
try:
payload = json.loads(raw)
except ValueError:
payload = None
if isinstance(payload, dict):
nodes = payload.get("nodes")
if not isinstance(nodes, list):
nodes = []
teams = {}
idle_names = []
total_hours = 0.0
total_cost = 0.0
scanned = 0
for node in nodes:
if not isinstance(node, dict):
continue
scanned += 1
name = str(node.get("node") or "unknown-node")
team = str(node.get("team") or "unassigned")
gpus = max(0, as_int(node.get("gpus")))
util = as_float(node.get("gpu_util_pct"))
idle_hours = max(0.0, as_float(node.get("idle_hours")))
row = teams.setdefault(team, {
"team": team,
"nodes_scanned": 0,
"idle_nodes": 0,
"attributed_hours": 0.0,
"attributed_cost_usd": 0.0,
})
row["nodes_scanned"] += 1
if util <= threshold and idle_hours >= min_idle:
hours = gpus * idle_hours
cost = hours * rate
idle_names.append(name)
total_hours += hours
total_cost += cost
row["idle_nodes"] += 1
row["attributed_hours"] = round(row["attributed_hours"] + hours, 2)
row["attributed_cost_usd"] = round(row["attributed_cost_usd"] + cost, 2)
team_rows = sorted(teams.values(), key=lambda r: r["attributed_cost_usd"], reverse=True)
worst_team = "none"
for row in team_rows:
if row["attributed_cost_usd"] > 0:
worst_team = row["team"]
break
outputs.update({
"scan_ok": True,
"billing_period": str(payload.get("billing_period") or "unknown"),
"nodes_scanned": scanned,
"idle_node_count": len(idle_names),
"idle_nodes": idle_names,
"attributed_hours": round(total_hours, 2),
"attributed_cost_usd": round(total_cost, 2),
"team_attribution": team_rows,
"worst_team": worst_team,
})
print("scan_ok=%s nodes=%d idle=%d hours=%.2f cost=%.2f worst=%s" % (
outputs["scan_ok"], outputs["nodes_scanned"], outputs["idle_node_count"],
outputs["attributed_hours"], outputs["attributed_cost_usd"], outputs["worst_team"]))
print("::" + json.dumps({"outputs": outputs}) + "::")
# --- 2. per team sweep ---
- id: review_teams
type: io.kestra.plugin.core.flow.Loop
description: Walk the scored team rows one at a time so every team carrying
charged idle hours gets its own alert with the exact node, hour and dollar
figures instead of one blended fleet message.
concurrencyLimit: 1
values: "{{ outputs.attribute_idle.vars.team_attribution }}"
tasks:
- id: flag_team
type: io.kestra.plugin.core.flow.If
description: Branch on the per team charged cost the scorer already computed,
keeping the utilization and idle duration policy in one place.
condition: "{{ item.value.attributed_cost_usd > 0 }}"
then:
- id: alert_team
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Post the team name, its idle node count, the attributed GPU-hours
and the charged dollars so the owning team can reclaim or
right-size the nodes.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "GPU idle cost for team {{ item.value.team }} in period {{ outputs.attribute_idle.vars.billing_period }} - {{ item.value.idle_nodes }} idle node(s) of {{ item.value.nodes_scanned }} scanned, {{ item.value.attributed_hours }} attributed GPU-hours at the {{ inputs.gpu_hourly_rate_usd }} USD hourly rate, {{ item.value.attributed_cost_usd }} USD charged. Policy is at or below {{ inputs.idle_utilization_threshold_pct }} percent utilization for at least {{ inputs.min_idle_hours }} idle hours. Execution {{ execution.id }}."
}
else:
- id: log_team_clean
type: io.kestra.plugin.core.log.Log
description: Record the clean team for the period so the execution history still
carries the full per team trail.
message: "Team {{ item.value.team }} clean in period {{
outputs.attribute_idle.vars.billing_period }} - all {{
item.value.nodes_scanned }} scanned GPU node(s) above policy,
nothing charged."
# --- 3. fleet verdict gate ---
- id: escalate_idle
type: io.kestra.plugin.core.flow.If
description: Branch on the fleet verdict so any policy-breaching idle node
escalates the totals and fails the run, while a fully consumed fleet is
logged and passes.
condition: "{{ outputs.attribute_idle.vars.scan_ok and
outputs.attribute_idle.vars.idle_node_count > 0 }}"
then:
- id: alert_fleet
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Post the fleet idle node count, the attributed GPU-hours, the
dollar total and the worst team so FinOps sees the full exposure in
one message.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{
"text": "GPU idle cost ESCALATION for period {{ outputs.attribute_idle.vars.billing_period }} - {{ outputs.attribute_idle.vars.idle_node_count }} idle node(s): {{ outputs.attribute_idle.vars.idle_nodes }}, {{ outputs.attribute_idle.vars.attributed_hours }} attributed GPU-hours, {{ outputs.attribute_idle.vars.attributed_cost_usd }} USD, worst team {{ outputs.attribute_idle.vars.worst_team }}. Billing keeps charging these nodes until they are reclaimed or right-sized. Execution {{ execution.id }}."
}
- id: fail_attribution
type: io.kestra.plugin.core.execution.Fail
description: Turn the run red so the cost pipeline stops instead of signing off
on a period with idle GPU capacity still billed.
errorMessage: "GPU idle attribution found {{
outputs.attribute_idle.vars.idle_node_count }} idle node(s) and {{
outputs.attribute_idle.vars.attributed_cost_usd }} USD of charged idle
cost, worst team {{ outputs.attribute_idle.vars.worst_team }}."
else:
- id: log_fleet_clean
type: io.kestra.plugin.core.log.Log
description: Record the clean fleet verdict with the scanned node count so a
quiet period still leaves evidence the attribution ran.
message: "GPU idle attribution clean for period {{
outputs.attribute_idle.vars.billing_period }} - {{
outputs.attribute_idle.vars.nodes_scanned }} node(s) scanned, none
below the {{ inputs.idle_utilization_threshold_pct }} percent
utilization policy, 0 USD charged."
errors:
- id: notify_failure
type: io.kestra.plugin.slack.notifications.SlackIncomingWebhook
description: Escalate any failure to the ops channel with the execution url.
url: "{{ secret('SLACK_WEBHOOK_URL') }}"
payload: |
{"text": "FAILED: {{ flow.id }} {{ execution.id }}"}
outputs:
- id: scan_ok
type: BOOL
description: True when the posted inventory parsed and scoring completed, false
for a malformed or unusable payload.
value: "{{ outputs.attribute_idle.vars.scan_ok }}"
- id: idle_node_count
type: INT
description: Number of GPU nodes that breached both the utilization threshold
and the minimum idle duration.
value: "{{ outputs.attribute_idle.vars.idle_node_count }}"
- id: idle_nodes
type: ARRAY
description: Names of the charged idle GPU nodes in inventory order, for example
gpu-node-h100-03.
value: "{{ outputs.attribute_idle.vars.idle_nodes }}"
- id: attributed_hours
type: FLOAT
description: Total charged GPU-hours across the fleet, computed as GPUs times
idle hours for every idle node.
value: "{{ outputs.attribute_idle.vars.attributed_hours }}"
- id: attributed_cost_usd
type: FLOAT
description: Idle GPU-hours multiplied by the blended hourly rate, the dollar
exposure handed to the owning teams.
value: "{{ outputs.attribute_idle.vars.attributed_cost_usd }}"
- id: team_attribution
type: ARRAY
description: Per team rows with scanned nodes, idle nodes, attributed GPU-hours
and charged USD, sorted by cost descending.
value: "{{ outputs.attribute_idle.vars.team_attribution }}"
- id: worst_team
type: STRING
description: Team carrying the largest charged idle cost this period, or none
when no node was charged.
value: "{{ outputs.attribute_idle.vars.worst_team }}"