New to Kestra?
Use blueprints to kickstart your first workflows.
Orchestrate ClickHouse cluster health monitoring with Kestra. Detect long-running table mutations and active partition parts bloat before query slowdowns occur.
ClickHouse relies on asynchronous background processes for table mutations (ALTER ... UPDATE / DELETE) and continuous part merges. Under heavy ingestion bursts, frequent single-row updates, or hardware resource constraints, two dangerous failure modes often emerge:
system.mutations consume CPU and disk I/O, hold table metadata locks, and can stall subsequent schema operations indefinitely if a part fails to rewrite.system.parts, eventually triggering ClickHouse's defensive "Too many parts in all data parts in table" error and rejecting further writes.This blueprint provides an automated, non-invasive health watchdog for ClickHouse clusters. It audits system.mutations for long-running mutations, analyzes system.parts for partition bloat exceeding operational thresholds, exports diagnostic metrics, and alerts database administrators and platform engineers on Slack with contextual remediation steps.
TOO_MANY_PARTS exceptions interrupt real-time streaming ingestion pipelines.check_stuck_mutations (io.kestra.plugin.jdbc.clickhouse.Query) queries system.mutations with fetchType: FETCH to find incomplete mutations (is_done = 0) that have been executing longer than inputs.max_mutation_age_minutes.check_partition_parts_explosion (io.kestra.plugin.jdbc.clickhouse.Query) scans system.parts for active data parts (active = 1) grouped by database, table, and partition, identifying partitions that exceed inputs.max_active_parts_threshold.emit_cluster_health_metrics (io.kestra.plugin.core.output.OutputValues) exports structured count metrics and cluster metadata into execution outputs.evaluate_cluster_health (io.kestra.plugin.core.flow.If) evaluates whether any stuck mutations or overloaded partitions were detected:notify_cluster_alert_slack dispatches a Slack notification with the offending table names, mutation IDs, part counts, failure reasons, and suggested operational commands.log_cluster_healthy records a success log.alert_on_failure in the errors block alerts on-call responders if network connectivity or authentication to ClickHouse fails.SELECT permissions on system.mutations and system.parts.Configure the following secrets in your Kestra namespace:
CLICKHOUSE_USERNAME: ClickHouse database user (e.g. default or sentinel_user).CLICKHOUSE_PASSWORD: Password for the ClickHouse user.SLACK_WEBHOOK_URL: Slack Incoming Webhook URL for diagnostic alerts.WEBHOOK_KEY: Authentication secret for manual on-demand execution via webhook.Adjust the flow inputs to match your cluster's operational profile:
clickhouse_url: ClickHouse JDBC connection URL (default: jdbc:clickhouse://clickhouse:8123/default).max_mutation_age_minutes: Maximum allowed execution age in minutes before a mutation is flagged as stuck (default: 60).max_active_parts_threshold: Maximum active parts per partition before parts explosion is flagged (default: 150).┌──────────────────────────────┐
│ Schedule / Webhook Trigger │
└──────────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ Check system.mutations │
└──────────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ Check system.parts (Active) │
└──────────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ Emit Health Metrics │
└──────────────┬───────────────┘
│
[Any Anomaly Detected?]
/ YES NO
/ ▼ ▼
┌───────────────┐ ┌───────────────┐
│ Dispatch │ │ Log Verified │
│ Slack Alert │ │ Clean Health │
└───────────────┘ └───────────────┘
stuck_mutations_count: 0, exploded_partitions_count: 0, and a confirmation log.io.kestra.plugin.jdbc.clickhouse.Queries task to run targeted OPTIMIZE TABLE ... PARTITION ... FINAL commands during off-peak hours for non-critical tables.system.merges to surface current background merge speed, disk read/write rates, and remaining merge durations.clusterAllReplicas(...) table functions to inspect mutations and parts across all distributed nodes simultaneously.