{"product_id":"n8n-kpi-anomaly-detection-postgres-slack-gmail-claude","title":"n8n KPI Anomaly Detection: Postgres + Slack + Gmail + Claude","description":"\u003ch3\u003eDetect KPI anomalies automatically—then investigate with Claude and notify the right owners in Slack, GitHub, and Gmail\u003c\/h3\u003e\n\u003cp\u003eThis n8n KPI Anomaly Detection workflow pulls daily KPIs from \u003cstrong\u003ePostgres\u003c\/strong\u003e, builds robust statistical baselines, detects unusual metric movements each morning, and automatically investigates confirmed anomalies using an \u003cstrong\u003eOpenRouter (Claude) agent\u003c\/strong\u003e with supporting evidence from \u003cstrong\u003ePostgres\u003c\/strong\u003e and \u003cstrong\u003eGitHub\u003c\/strong\u003e. Alerts are routed by severity to \u003cstrong\u003eSlack\u003c\/strong\u003e, \u003cstrong\u003eGitHub Issues\u003c\/strong\u003e (for critical), and \u003cstrong\u003eGmail\u003c\/strong\u003e—plus a weekly precision report.\u003c\/p\u003e\n\n\u003ch3\u003eWhat this workflow does\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eNightly KPI collection (01:00)\u003c\/strong\u003e: Reads enabled metric definitions from Postgres, executes each metric’s SQL, and stores yesterday’s observations.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eRobust baseline recomputation\u003c\/strong\u003e: Rebuilds per-metric baselines in Postgres using a \u003cstrong\u003e28-day median\u003c\/strong\u003e and \u003cstrong\u003eMAD\u003c\/strong\u003e, with \u003cstrong\u003eday-of-week medians\u003c\/strong\u003e. Tracks baseline coverage and warns in Slack if history is insufficient.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eMorning anomaly scoring (07:00)\u003c\/strong\u003e: Pulls yesterday’s KPI values joined with baseline stats and metric metadata from Postgres.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eRobust z-score anomaly detection\u003c\/strong\u003e: Scores each KPI move into a robust z-score, applies direction and minimum-change rules, filters anomalies, and suppresses duplicates using recent open incidents and a per-run incident cap.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eAutomated investigation with Claude\u003c\/strong\u003e: For each admitted anomaly, creates an incident record in Postgres, then queries Postgres and GitHub via an OpenRouter (Claude) agent for supporting evidence; explanations failing an evidence\/consistency check are discarded.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eSeverity-based routing\u003c\/strong\u003e: Updates the incident with the investigation outcome and notifies owners via Slack; for critical alerts, also files a GitHub Issue and emails the metric owner for acknowledgement.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eUse cases\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003eSaaS teams monitoring conversion rate, retention, and latency KPIs across daily shifts\u003c\/li\u003e\n  \u003cli\u003eAutomation engineers needing trustworthy KPI anomaly detection with duplicate suppression\u003c\/li\u003e\n  \u003cli\u003eOperators who want Slack-first alerts plus deeper investigation context via Claude\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eTechnical details\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eData source\u003c\/strong\u003e: Postgres (metric definitions, observations, baselines, incident records)\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eAI investigator\u003c\/strong\u003e: OpenRouter (Claude) agent with Postgres + GitHub evidence queries\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eNotifications\u003c\/strong\u003e: Slack (warnings + anomaly alerts), GitHub Issues (critical), Gmail (owner acknowledgement)\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eWorkflow nodes\u003c\/strong\u003e: if, set, code, gmail, merge, slack\u003c\/li\u003e\n\u003c\/ul\u003e","brand":"N8N Commerce","offers":[{"title":"Default Title","offer_id":46072076173491,"sku":"N8N-19804","price":32.99,"currency_code":"GBP","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0749\/6279\/6723\/files\/s2aWU5NzfdiEIgd55_QwI_FLRIdwnC.png?v=1790067912","url":"https:\/\/buyflowscripts.com\/products\/n8n-kpi-anomaly-detection-postgres-slack-gmail-claude","provider":"N8N Commerce","version":"1.0","type":"link"}