{"product_id":"postgres-kpi-anomaly-detection-with-slack-github-gmail","title":"Postgres KPI Anomaly Detection with Slack, GitHub \u0026 Gmail","description":"\u003ch3\u003eDetect Postgres KPI anomalies and send actionable alerts to Slack, GitHub, and Gmail—automatically\u003c\/h3\u003e\n\u003cp\u003eThis n8n workflow monitors daily KPI health stored in \u003cstrong\u003ePostgres\u003c\/strong\u003e, builds robust statistical baselines, detects true anomalies using median\/MAD scoring, and routes incident alerts to \u003cstrong\u003eSlack\u003c\/strong\u003e, \u003cstrong\u003eGitHub\u003c\/strong\u003e, and \u003cstrong\u003eGmail\u003c\/strong\u003e with an \u003cstrong\u003eOpenRouter (Claude)\u003c\/strong\u003e-generated investigation summary and feedback reporting.\u003c\/p\u003e\n\n\u003ch3\u003eWhat this workflow does\u003c\/h3\u003e\n\u003cp\u003eThe workflow is designed for reliable KPI anomaly detection and clear operational routing:\u003c\/p\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eDaily ingestion (01:00):\u003c\/strong\u003e Runs on-demand or nightly at \u003cstrong\u003e01:00\u003c\/strong\u003e to load enabled metric definitions from Postgres, execute each metric’s SQL, and store \u003cstrong\u003eyesterday’s observation\u003c\/strong\u003e in a \u003cstrong\u003ekpi_observations\u003c\/strong\u003e table.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eRobust baseline rebuild:\u003c\/strong\u003e Recomputes per-metric baselines in Postgres using a \u003cstrong\u003e28-day median\u003c\/strong\u003e and \u003cstrong\u003eMAD\u003c\/strong\u003e, including \u003cstrong\u003eday-of-week medians\u003c\/strong\u003e. It logs baseline coverage and posts a \u003cstrong\u003eSlack warning\u003c\/strong\u003e when history is insufficient to score.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eDaily anomaly scoring (07:00):\u003c\/strong\u003e At \u003cstrong\u003e07:00\u003c\/strong\u003e, it fetches yesterday’s observations joined with baseline and registry settings, then calculates robust z-scores, severity, and skip reasons.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eDuplicate suppression:\u003c\/strong\u003e Checks recent \u003cstrong\u003eopen\/acknowledged incidents\u003c\/strong\u003e in Postgres and enforces a per-run incident cap. Suppressed alerts are logged for auditability.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eIncident investigation with Claude:\u003c\/strong\u003e For each new incident, creates an incident record in Postgres and uses an \u003cstrong\u003eOpenRouter (Claude)\u003c\/strong\u003e agent with \u003cstrong\u003ePostgres\u003c\/strong\u003e and \u003cstrong\u003eGitHub\u003c\/strong\u003e tools to investigate, validates the explanation against evidence, and updates the incident.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eSeverity-based routing:\u003c\/strong\u003e Sends \u003cstrong\u003eSlack\u003c\/strong\u003e messages for critical and warning levels, opens a \u003cstrong\u003eGitHub issue\u003c\/strong\u003e for critical incidents, and triggers a \u003cstrong\u003eGmail acknowledgement request\u003c\/strong\u003e. Notification status is recorded back into Postgres.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eUse cases\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003eCatch abnormal KPI drops\/spikes in a production SaaS before they impact customers.\u003c\/li\u003e\n  \u003cli\u003eAutomate incident triage with consistent statistical scoring and duplicate suppression in Postgres.\u003c\/li\u003e\n  \u003cli\u003eNotify engineering in Slack, create GitHub issues for critical anomalies, and request acknowledgment via Gmail.\u003c\/li\u003e\n  \u003cli\u003eProvide weekly precision reporting and capture feedback via a webhook.\u003c\/li\u003e\n\u003c\/ul\u003e\n\n\u003ch3\u003eTechnical details\u003c\/h3\u003e\n\u003cul\u003e\n  \u003cli\u003e\n\u003cstrong\u003eCore logic:\u003c\/strong\u003e baseline generation (28-day median, MAD, day-of-week medians) and robust z-score anomaly detection.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eIntegrations \/ nodes:\u003c\/strong\u003e \u003cstrong\u003eSlack\u003c\/strong\u003e, \u003cstrong\u003eGitHub\u003c\/strong\u003e, \u003cstrong\u003eGmail\u003c\/strong\u003e, plus workflow control nodes like \u003cstrong\u003eif\u003c\/strong\u003e, \u003cstrong\u003eset\u003c\/strong\u003e, \u003cstrong\u003ecode\u003c\/strong\u003e, and \u003cstrong\u003emerge\u003c\/strong\u003e.\u003c\/li\u003e\n  \u003cli\u003e\n\u003cstrong\u003eData storage:\u003c\/strong\u003e Postgres tables including \u003cstrong\u003ekpi_observations\u003c\/strong\u003e and incident\/notification status tracking.\u003c\/li\u003e\n\u003c\/ul\u003e","brand":"N8N Commerce","offers":[{"title":"Default Title","offer_id":45950339055795,"sku":"N8N-19059","price":28.99,"currency_code":"GBP","in_stock":true}],"thumbnail_url":"\/\/cdn.shopify.com\/s\/files\/1\/0749\/6279\/6723\/files\/2YUTqEDX9CK27E6Mffr_t_cLAvxIIA.png?v=1788514770","url":"https:\/\/buyflowscripts.com\/products\/postgres-kpi-anomaly-detection-with-slack-github-gmail","provider":"N8N Commerce","version":"1.0","type":"link"}