FinOps Sentinel: Anomalieerkennung mit TimescaleDB und Google Gemini in Kestra
Für eine Hacktoberfest-Challenge ist ein Community-Blueprint für Kestra entstanden, der Cloud-Ausgaben in Echtzeit automatisch überwacht. Die Kombination aus TimescaleDB und Google Gemini AI soll Kostenanomalien eigenständig erkennen.

Im Rahmen der dieswöchigen Hacktoberfest Open-Source AI & Database Challenge habe ich einen offiziellen Community-Blueprint für Kestra erstellt und eingereicht: den Autonomous TimescaleDB + Gemini AI FinOps Sentinel.
Er bildet ein Echtzeit-Überwachungssystem für Finanzen ab, das Cloud-Ausgaben-Zeitreihen in TimescaleDB Continuous Aggregates (CAGGs) überwacht, statistische Ausgabenspitzen erkennt, Google Gemini 1.5 Flash für eine kontextbezogene Ursachenanalyse aufruft und Remediation-Alerts direkt in Slack orchestriert.
🐙 Upstream Pull Request: kestra-io/blueprints (Timescale + Gemini Sentinel) 🐯 Database Engine: TimescaleDB / Tiger Cloud 🤖 AI Engine: Google Gemini 1.5 Flash API ⚡ Workflow Orchestrator: Kestra Das Problem: Die "stille Explosion der Cloud-Rechnung"
Jedes Engineering-Team kennt die gefürchtete Überraschung bei der monatlichen Cloud-Abrechnung:
Unkoordiniertes Provisioning: Ein Entwickler startet On-Demand-GPU-Cluster (p4d.24xlarge) oder eine ungedrosselte LLM-Embedding-Pipeline und vergisst, sie am Freitagabend wieder zu beenden. Statische Alert-Ermüdung: Traditionelle Alerts basieren auf starren Schwellenwertregeln (zum Beispiel "benachrichtigen, wenn die Ausgaben > 1.000 $ sind"). Wenn das Basisaufkommen natürlich wächst, melden die Alerts ständig falsche Alarme und die Ingenieure ignorieren sie.
Fehlender Kontext: Eine reine Metrik-Benachrichtigung wie [ALERT] Die Ausgaben liegen bei 3.200 $ erklärt nicht, warum sie gestiegen sind oder was zu tun ist, wodurch On-Call-Ingenieure stundenlang rohe AWS-/GCP-Dashboards durchforsten müssen. Die Architektur [TimescaleDB Hypertables & CAGGs] │ ▼ (stündliche Rollups) [Statistische Z-Score-Anomalieisolierung] │ ▼ (Anomalie-JSON-Payload) [Google Gemini 1.5 Flash Root-Cause-Diagnose] │ ▼ (strukturiertes JSON: Severity + Remedy) [Kestra deklarative Flow-Steuerung (wenn Severity >= HIGH)] ┌─────┴─────┐ ▼ ▼ [CRITICAL/HIGH] [NOMINAL] │ │ ├─► [Slack Block Kit Alert] └─► [Kestra Audit Trail KV Store] So funktioniert es in Kestra
Die gesamte Pipeline ist als ereignisgesteuerter, deklarativer Workflow in Kestra orchestriert (timescale-gemini-financial-anomaly-sentinel.yaml):
Der Workflow wird zu jeder vollen Stunde ausgelöst (io.kestra.plugin.core.trigger.Schedule). Er berechnet rollierende Standardabweichungen über aktuelle stündliche Buckets aus den Timescale Continuous Aggregates:
for cat in categories: mean = sum(baseline_spends) / len(baseline_spends) variance = sum((x - mean) ** 2 for x in baseline_spends) / len(baseline_spends) std_dev = math.sqrt(variance) if variance > 0 else 1.0 z_score = (current_spend - mean) / std_dev if z_score >= threshold: anomalies.append({ "category": cat, "current_spend_usd": round(current_spend, 2), "historical_mean_usd": round(mean, 2), "z_score": round(z_score, 2), "percentage_spike": round(((current_spend - mean) / mean) * 100, 1), "vendor_hints": ["AWS US-East GPU instances", "Overlapping on-demand EC2 clusters"] })
Statt eine kryptische Zahl an Slack zu senden, wird der Anomalie-Vektor an Google Gemini 1.5 Flash übergeben. Gemini bewertet die historische Varianz, korreliert Vendor-Hinweise und gibt eine strukturierte Incident-Antwort aus:
json { "severity": "CRITICAL", "summary": "Cloud Infrastructure spend surged by 470% (Z-Score: 4.2) due to uncoordinated on-demand GPU instance provisioning.", "remediation_action": "Audit active AWS us-east EC2 clusters and terminate orphaned p4d.24xlarge on-demand instances immediately.", "urgency_score": 9 }
Kestras io.kestra.plugin.core.flow.If wertet die von Gemini zurückgegebene Dringlichkeit aus:
Bei CRITICAL oder HIGH: Der Workflow formatiert einen interaktiven Slack-Block-Kit-Alert für #finops-alerts mit den konkreten Remediation-Schritten und schreibt die Incident-ID in Kestras persistenten KV-Store. Bei LOW oder MODERATE: Er protokolliert still den Nominalstatus und eliminiert damit vollständig die Alert-Ermüdung.
Continuous Aggregates in Timescale + AI = Echtzeit-FinOps: Die Berechnung rollierender Metriken auf rohen Transaktionstabellen dauert mehrere hundert Millisekunden; Timescales Continuous Aggregates berechnen die Zeit-Buckets vorab und ermöglichen so eine Anomalie-Zuführung zu Gemini im Sub-Millisekundenbereich. KI-angereicherte Alerts verändern das Incident-Response: Ein On-Call-Ingenieur, der eine vorab diagnostizierte Slack-Benachrichtigung mit sofortigen Handlungsschritten erhält, kann Vorfälle in Minuten lösen, statt stundenlang Dashboard-Diagrammen hinterherzujagen.
Die Kraft von Open Source: Da dies als upstream Kestra Blueprint verpackt ist, kann jedes Team, das Kestra und PostgreSQL einsetzt, diesen automatisierten Sentinel in weniger als 5 Minuten deployen.
Gebaut mit TimescaleDB, Google Gemini und Kestra für das Hacktoberfest 2026!
Automatisch übersetzt. Das Original auf Englisch ist unten aufklappbar.
Original (Englisch) anzeigen
For this week's Hacktoberfest Open-Source AI & Database Challenge, I built and submitted an official community blueprint to Kestra: the Autonomous TimescaleDB + Gemini AI FinOps Sentinel.
It creates a real-time, automated financial surveillance system that monitors cloud spending timeseries in TimescaleDB Continuous Aggregates (CAGGs), detects statistical spending spikes, invokes Google Gemini 1.5 Flash for contextual root-cause diagnosis, and orchestrates remediation alerts directly into Slack.
🐙 Upstream Pull Request: kestra-io/blueprints (Timescale + Gemini Sentinel) 🐯 Database Engine: TimescaleDB / Tiger Cloud 🤖 AI Engine: Google Gemini 1.5 Flash API ⚡ Workflow Orchestrator: Kestra The Problem: The "Silent Cloud Bill Surge"
Every engineering team has experienced the dreaded end-of-month cloud billing surprise:
Uncoordinated Provisioning: A developer spins up on-demand GPU clusters (p4d.24xlarge) or an unthrottled LLM embedding pipeline, forgetting to terminate it on Friday night. Static Alert Fatigue: Traditional alerts rely on rigid threshold rules (e.g., "notify if spend > $1,000"). When baseline traffic naturally grows, alerts cry wolf and engineers ignore them.
Missing Context: A raw metric alert like [ALERT] Spend is $3,200 doesn't explain why it spiked or what to do, forcing on-call engineers to spend hours triaging raw AWS/GCP dashboards. The Architecture [TimescaleDB Hypertables & CAGGs] │ ▼ (Hourly Rollups) [Statistical Z-Score Anomaly Isolation] │ ▼ (Anomaly JSON Payload) [Google Gemini 1.5 Flash Root-Cause Diagnosis] │ ▼ (Structured JSON: Severity + Remedy) [Kestra Declarative Flow Control (If Severity >= HIGH)] ┌─────┴─────┐ ▼ ▼ [CRITICAL/HIGH] [NOMINAL] │ │ ├─► [Slack Block Kit Alert] └─► [Kestra Audit Trail KV Store] How It Works in Kestra
The entire pipeline is orchestrated as an event-driven declarative workflow in Kestra (timescale-gemini-financial-anomaly-sentinel.yaml):
The workflow triggers at the top of every hour (io.kestra.plugin.core.trigger.Schedule). It calculates rolling standard deviations over recent hourly buckets from Timescale continuous aggregates:
for cat in categories: mean = sum(baseline_spends) / len(baseline_spends) variance = sum((x - mean) ** 2 for x in baseline_spends) / len(baseline_spends) std_dev = math.sqrt(variance) if variance > 0 else 1.0 z_score = (current_spend - mean) / std_dev if z_score >= threshold: anomalies.append({ "category": cat, "current_spend_usd": round(current_spend, 2), "historical_mean_usd": round(mean, 2), "z_score": round(z_score, 2), "percentage_spike": round(((current_spend - mean) / mean) * 100, 1), "vendor_hints": ["AWS US-East GPU instances", "Overlapping on-demand EC2 clusters"] })
Rather than sending a cryptic number to Slack, the anomaly vector is dispatched to Google Gemini 1.5 Flash. Gemini evaluates historical variance, correlates vendor hints, and outputs a structured incident response:
json { "severity": "CRITICAL", "summary": "Cloud Infrastructure spend surged by 470% (Z-Score: 4.2) due to uncoordinated on-demand GPU instance provisioning.", "remediation_action": "Audit active AWS us-east EC2 clusters and terminate orphaned p4d.24xlarge on-demand instances immediately.", "urgency_score": 9 }
Kestra's io.kestra.plugin.core.flow.If evaluates the urgency returned by Gemini:
If CRITICAL or HIGH: It formats an interactive Slack Block Kit alert directed at #finops-alerts with the exact remediation steps, and commits the incident ID into Kestra's persistent KV store. If LOW or MODERATE: It silently logs nominal status, completely eliminating alert fatigue.
Continuous Aggregates in Timescale + AI = Real-Time FinOps: Calculating rolling metrics on raw transaction tables takes hundreds of milliseconds; Timescale's continuous aggregates pre-compute the time buckets, enabling sub-millisecond anomaly feeds into Gemini. AI-Enriched Alerts Change Incident Response: An on-call engineer receiving a pre-diagnosed Slack notification with immediate action items can resolve incidents in minutes rather than spending hours chasing dashboard charts.
Open-Source Power: By packaging this as an upstream Kestra Blueprint, any team running Kestra and PostgreSQL can deploy this automated sentinel in under 5 minutes.
Built with TimescaleDB, Google Gemini, and Kestra for Hacktoberfest 2026!