Script icon
Docker icon
If icon
SlackIncomingWebhook icon
Log icon
Return icon
Schedule icon

Longhorn Volume Replica Degraded and Rebuild Sentinel

Scrapes Longhorn Prometheus metrics to track degraded volumes, faulted replicas, and rebuilding status with Slack alerting.

Categories
CloudInfrastructure

Production-grade cloud-native storage reliability watchdog that continuously monitors Longhorn distributed block storage deployments. It tracks volume robustness states across Persistent Volume Claims (PVCs), detects degraded volumes operating below desired replica counts, identifies faulted disk replicas, and dispatches structured Slack alerts before node evictions cause unrecoverable data loss in Kubernetes stateful workloads.

How it works

  1. A recurring schedule trigger wakes the flow every 15 minutes to initiate Longhorn storage surveillance.
  2. A containerized Python script polls the Longhorn backend Prometheus metrics endpoint (:9500/metrics).
  3. The script extracts volume robustness states (longhorn_volume_robustness) to detect degraded and faulted volumes.
  4. The script audits rebuilding replica counters and identifies storage nodes experiencing disk allocation pressure.
  5. A decision gate evaluates whether degraded volume counts or faulted replicas breach enterprise storage thresholds.
  6. When durability risks emerge, high-priority notifications dispatch to Storage SRE channels with diagnostic runbooks.
  7. A structured audit manifest is emitted for enterprise compliance records and persistent volume telemetry archives.

Architecture diagram

flowchart TD
    A[Schedule Trigger: Every 15 Mins] --> B[scan_longhorn_volume_metrics]
    B --> C{evaluate_longhorn_threshold}
    C -- Alert Triggered --> D[notify_slack_storage_team]
    C -- Nominal State --> E[log_nominal_longhorn_state]
    D --> F[emit_audit_manifest]
    E --> F[emit_audit_manifest]

Architecture components

  • Trigger (periodic_longhorn_audit): Recurring cron schedule executing every 15 minutes for proactive storage surveillance.
  • Scraper Task (scan_longhorn_volume_metrics): Docker-isolated Python script polling Longhorn metrics with error handling.
  • Decision Gate (evaluate_longhorn_threshold): Evaluates degraded volume counts and faulted replicas against user thresholds.
  • Notification Task (notify_slack_storage_team): Sends rich Slack alert with degraded counts, faulted disks, and runbooks.
  • Compliance Manifest (emit_audit_manifest): Emits structured JSON summary for storage audit archives.

Key capabilities

  • Continuous surveillance of distributed volume replica health across Kubernetes worker nodes.
  • Early warning when volume robustness drops from healthy to degraded following node reboot.
  • Detection of failed snapshot rebuild loops before node disk storage capacity fills completely.
  • Standardized Slack alerting with operational runbook instructions for storage administrators.

What you get

  • Real-time visibility into Longhorn block storage durability and replica synchronization status.
  • Protection against data loss in stateful database pods running on distributed Kubernetes clusters.
  • Automated Slack incident notifications with volume health states and recovery instructions.
  • Clean compliance manifests recording storage cluster durability for SRE audit trails.

Who it's for

  • Kubernetes Storage Administrators managing enterprise Longhorn distributed volume pools.
  • Site Reliability Engineers safeguarding stateful databases and persistent application volumes.
  • Cloud Infrastructure Engineers operating bare-metal and private cloud container platforms.
  • DevOps Teams operating high-I/O workloads, stateful sets, and persistent messaging clusters.

Why orchestrate this with Kestra

  • Decoupled Architecture: Scrapes metrics externally without requiring privileged host root access.
  • Deterministic Scheduling: Native cron scheduling ensures consistent surveillance without cron daemon drift.
  • Isolated Execution: Runs Python scrapers inside isolated Docker containers with pre-installed libraries.
  • Enterprise Auditability: Generates structured execution histories and JSON manifests for regulatory reporting.

Use cases

  • Post-Maintenance Volume Recovery: Verify that volumes rebuild third replicas following scheduled node maintenance.
  • Node Eviction Cascade Prevention: Detect when a single disk failure puts multiple stateful databases at risk.
  • Disk Space Over-Allocation: Identify storage nodes exceeding Longhorn storage reservation thresholds.
  • Engine Instance Manager Crashes: Catch volume detached events caused by container engine instance manager restarts.

Inputs

Name Type Default Description
longhorn_metrics_url STRING http://longhorn-backend.longhorn-system.svc.cluster.local:9500 Base HTTP URL exposing Longhorn Prometheus metrics.
storage_pool STRING production-nvme-pool Target Longhorn storage pool identifier under active surveillance.
max_degraded_volumes_threshold INT 2 Maximum allowable degraded volumes before alerting.
lookback_minutes INT 15 Lookback evaluation window in minutes for storage telemetry.
alert_on_longhorn_failures BOOL true Toggle Slack alert dispatch upon detecting degraded volumes or stalls.

Expected outputs

  • {{ outputs.scan_longhorn_volume_metrics.vars.degraded_volumes_count }}: Cumulative count of volumes operating with reduced replicas.
  • {{ outputs.scan_longhorn_volume_metrics.vars.rebuilding_volumes_count }}: Count of volume replicas actively undergoing resynchronization.
  • {{ outputs.scan_longhorn_volume_metrics.vars.faulted_replicas_count }}: Total number of replicas marked as permanently faulted.
  • {{ outputs.scan_longhorn_volume_metrics.vars.healthy_volumes_total }}: Total number of volumes operating with full replica health.
  • {{ outputs.scan_longhorn_volume_metrics.vars.is_alerting }}: Boolean flag indicating whether failure thresholds were breached.
  • {{ outputs.emit_audit_manifest.value }}: Structured JSON audit manifest emitted for compliance archives.

Prerequisites

  • Longhorn deployed in Kubernetes cluster with metrics service enabled on port 9500.
  • Longhorn metrics port reachable from the Kestra worker execution environment.
  • Docker daemon running on the Kestra host to execute containerized Python tasks.

Secrets

  • SLACK_WEBHOOK_URL: Incoming webhook URL for the target Storage SRE Slack alerting channel.

Quick start

  1. Ensure Longhorn backend service in longhorn-system exposes port 9500.
  2. Configure the SLACK_WEBHOOK_URL secret in your Kestra namespace settings.
  3. Specify your storage pool identifier in storage_pool.
  4. Execute a manual test run via the Kestra UI to verify metric ingestion.
  5. Enable the periodic_longhorn_audit trigger to establish automated continuous surveillance.

Common pitfalls and troubleshooting

  • Disk Space Exhaustion: If a node disk exceeds 90%, Longhorn refuses to schedule new replica rebuilds.
  • Network Latency Spikes: High latency on the storage replication network triggers false replica timeout faults.
  • Snapshot Accumulation: Leaving hundreds of snapshots unpurged degrades rebuild speeds and balloons metadata size.
  • Engine Instance Manager Crash: Heavy load can crash instance-manager-e pods; inspect pod restart counters.

How to extend

  • Automated Replica Purge: Chain a task to delete stuck faulted replicas via the Longhorn REST API.
  • Dynamic Storage Node Rebalance: Trigger a sub-flow to rebalance volume replicas away from congested worker nodes.
  • PagerDuty Escalation: Escalate to on-call storage engineers if faulted replicas exceed 3 for over 15 minutes.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.