Schedule icon
Webhook icon
WorkingDirectory icon
Commands icon
Docker icon
Script icon
If icon
Loop icon
Log icon
SlackIncomingWebhook icon

Ollama Model Storage Headroom and Cache Eviction Sentinel

Audit Ollama model disk usage, detect capacity exhaustion, alert Slack, and safely prune stale unpinned weights before host storage runs out.

Categories
AIInfrastructure

Self-hosted LLM runners and local AI inference clusters powered by Ollama frequently pull multi-gigabyte model weights (e.g., LLaMA, DeepSeek, Qwen) for local evaluation and batch inference. Because Ollama does not enforce an automated retention or eviction policy, host and container disk volumes silently saturate over time, eventually crashing worker nodes or freezing Docker runtimes.

This blueprint provides an automated storage sentinel that audits Ollama's local model registry, safeguards currently running VRAM workloads and pinned models, calculates disk usage against an operational headroom ceiling, escalates capacity alerts to Slack, and safely reclaims disk space.

How it works

  1. nightly_headroom_scan (io.kestra.plugin.core.trigger.Schedule, cron 0 3 * * *, shipped disabled: true) runs automated daily sweeps during off-peak hours. on_demand_audit (io.kestra.plugin.core.trigger.Webhook) allows external CI/CD or ChatOps triggers to run on-demand storage checks.
  2. audit_workspace (io.kestra.plugin.core.flow.WorkingDirectory) mounts a dedicated shared scratch space so the API query and analysis scripts share files cleanly.
  3. probe_ollama (io.kestra.plugin.scripts.shell.Commands in curlimages/curl:8.9.1) issues GET /api/tags and GET /api/ps to probe installed models, disk sizes, and active VRAM instances. If the endpoint is offline, it safely falls back to bundled fixtures to ensure offline testability.
  4. analyze_capacity (io.kestra.plugin.scripts.python.Script in python:3.12-slim) parses the JSON payloads, excludes active processes and pinned protected_models, calculates total gigabytes consumed, identifies eviction candidates older than min_retention_days, generates ollama-storage-report.txt, and emits the verdict via Kestra's outputs protocol.
  5. evaluate_headroom (io.kestra.plugin.core.flow.If) branches on the verdict:
    • On CAPACITY_BREACH: If auto_prune is authorized, prune_excess_models iteratively calls DELETE /api/delete for identified stale models to restore headroom, and notify_slack_alert posts an incident card with exact storage metrics to Slack.
    • On HEALTHY: log_healthy records a nominal audit entry for observability.
  6. The errors block alerts Slack if any step encounters unhandled connection or container failures.

What you get

  • Automated disk exhaustion prevention for self-hosted AI runners and edge inference nodes.
  • Active process protection: Models currently loaded in GPU VRAM or RAM are automatically excluded from deletion.
  • Whitelist pinning: Critical foundation and embedding models listed in protected_models are strictly protected.
  • Actionable capacity alerts with detailed breakdown of model counts, excess gigabytes, and candidate models.
  • Comprehensive audit trail report (ollama-storage-report.txt) saved directly to Kestra internal storage.

Who it's for

  • Platform Engineers and MLOps Teams managing self-hosted AI workers and GPU nodes.
  • AI Engineers deploying local Ollama models in CI/CD or staging environments.
  • Site Reliability Engineers safeguarding inference servers against out-of-disk crashes.

Why orchestrate this with Kestra

Scripting an ad-hoc cron job with bash or python lacks state management, webhook triggers, execution history, and team visibility. Orchestrating with Kestra provides declarative configuration, centralized secret masking for webhook tokens and Slack integrations, automatic retries, and a web UI where operators can inspect storage trends or manually trigger reclamation with custom thresholds.

Prerequisites

  • A Kestra worker with Docker task runner enabled.
  • Network connectivity from the Kestra worker to the Ollama API daemon (http://localhost:11434 or custom URL).
  • A Slack incoming webhook for capacity warnings and failure notifications.

Secrets

  • OLLAMA_WEBHOOK_KEY: Secret authentication key guarding the on-demand webhook trigger URL.
  • SLACK_WEBHOOK_URL: Slack Incoming Webhook URL for capacity warnings and error notifications.

Quick start

  1. Add OLLAMA_WEBHOOK_KEY and SLACK_WEBHOOK_URL to your Kestra namespace secrets.
  2. Import this blueprint into your Kestra instance.
  3. Click Execute with default parameters to run an initial audit; verify that verdict and total_disk_gb appear in execution outputs.
  4. Review ollama-storage-report.txt in the execution Outputs tab.
  5. When ready for production, enable the nightly_headroom_scan schedule trigger.

How to extend

  • Add Prometheus push gateway metrics emission to chart Ollama disk usage trends over time.
  • Connect downstream workflows to automatically trigger a model pull if a pruned model is requested again.
  • Add multi-host loop orchestration to audit a cluster of Ollama worker nodes in parallel.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.