Schedule icon
Request icon
Script icon
Switch icon
Log icon
SlackIncomingWebhook icon

Fly.io Zombie Machine & Volume FinOps Sentinel

Audit Fly.io apps on a schedule to detect stopped zombie machines and unattached NVMe volumes before idle infrastructure drives up monthly cloud spend.

Categories
CloudInfrastructure

Modern container platforms like Fly.io allow development and DevOps teams to spin up lightweight, hardware-virtualized machines and attached NVMe volumes globally in seconds. However, during continuous deployment rollouts, ephemeral staging tests, and autoscaling scale-down events, stopped machines and unattached persistent volumes frequently remain provisioned in the account. Because cloud providers bill for provisioned NVMe storage allocations and reserved capacity even while machines sit in a stopped state, abandoned resources accumulate into substantial monthly cloud bill leaks.

This blueprint implements an automated Day 2 FinOps sentinel for Fly.io applications. Operating on a periodic weekly or custom schedule, it directly inspects the Fly.io Machines API, evaluates stopped instance durations against configured inactivity thresholds, estimates monthly wasted spend, and dispatches rich Slack alert cards with ready-to-run flyctl teardown directives.

How it works

  1. Scheduled Invocation: The workflow executes on a periodic schedule (0 9 * * 1, every Monday at 09:00 UTC, shipped disabled for initial configuration) or on demand.
  2. Fly.io Machines Query: fetch_fly_machines executes an HTTP GET request to https://api.machines.dev/v1/apps/{{ inputs.fly_app_name }}/machines via io.kestra.plugin.core.http.Request, authenticating with the bearer token secret FLY_API_TOKEN.
  3. Python Metric Extraction: parse_and_classify_zombies executes inside an isolated python:3.11-slim container, parsing all machine JSON objects. It filters for stopped or suspended states and evaluates updated_at against stale_days_threshold.
  4. Operational Branching: evaluate_finops_waste utilizes io.kestra.plugin.core.flow.Switch to evaluate the classified status:
    • When Healthy: Emits an audit log confirming zero stale instances across all machines.
    • When Zombies Detected: Invokes io.kestra.plugin.slack.notifications.SlackIncomingWebhook to dispatch a formatted FinOps card to #finops-alerts detailing offending machine IDs, regions, inactivity days, and estimated waste.
  5. Telemetry Logging: log_audit_completion records the overall audit summary and instance counts.
  6. Error Resilience: A dedicated errors handler catches HTTP connection timeouts or authentication failures, ensuring on-call teams are alerted if the health check itself cannot reach the API.

What you get

  • Automated Cloud Cost Hygiene: Continuous inspection prevents abandoned staging machines and testing deployments from silently billing for weeks.
  • Zero Infrastructure Footprint: Runs completely serverless using Kestra native tasks and containerized Python parsing, requiring no persistent monitoring agents.
  • Actionable Slack Alerts: Context-rich Slack messages direct DevOps and platform engineers immediately to the offending machine ID with concrete flyctl deletion commands.
  • Configurable Aging Thresholds: Tailor the inactivity window (default 7 days) to distinguish legitimate standby machines from forgotten zombie instances.

Who it's for

  • Platform Engineers & DevOps Teams managing microservice clusters and edge applications deployed on Fly.io.
  • FinOps Leaders & Engineering Managers monitoring cloud infrastructure budgets and eliminating idle capacity waste.
  • Site Reliability Engineers (SREs) maintaining infrastructure cleanliness and container lifecycle management.

Why orchestrate this with Kestra

Writing custom bash cron scripts to poll cloud APIs creates unmonitored cron jobs, unmasked secrets, and brittle alert plumbing. Kestra provides:

  • Declarative YAML Orchestration: The entire monitoring and alert topology is codified in version-controlled YAML with transparent execution history.
  • Encrypted Secret Management: Fly.io API tokens and Slack incoming webhook URLs remain securely encrypted and masked in all execution logs.
  • Built-in Flow Logic: Native Switch branching and containerized Python scripts provide robust error recovery without external microservice dependencies.

Prerequisites

  • A Fly.io account and application with an API token from fly.io/dashboard.
  • An incoming Slack webhook URL for operational alerting.

Secrets

Configure the following secrets in your Kestra namespace or instance settings:

Secret Name Description Example
FLY_API_TOKEN Fly.io personal access token or deploy token fo1_••••••••••••
SLACK_WEBHOOK Incoming webhook URL for destination Slack channel https://hooks.slack.com/services/T00/B00/X00

Quick start

  1. In Kestra, navigate to Flows and import this blueprint into your designated namespace (e.g., company.cloud).
  2. Add your FLY_API_TOKEN and SLACK_WEBHOOK into Settings > Secrets.
  3. Click Execute and provide your fly_app_name to test the audit pass.
  4. Review execution logs to verify machine parsing and ensure the Slack alert card renders properly.
  5. In the flow definition, toggle disabled: false on periodic_finops_audit to activate the automated weekly monitoring schedule.

How to extend

  • Automated Destruction Workflow: Chain an automated teardown task with io.kestra.plugin.core.http.Request (DELETE https://api.machines.dev/v1/apps/.../machines/{id}?force=true) when remediation_mode == 'AUTO_DESTROY'.
  • Volume Attachment Inspection: Extend the Python script to cross-reference attached_volume_id with /v1/apps/{app}/volumes to detect orphan unattached storage volumes.
  • Multi-App Inspection: Replace the single app input with io.kestra.plugin.core.flow.Loop to audit all organization apps in parallel.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.