Real-Time Monitoring and Alerting with SQL
Real-time monitoring tracks system health, application metrics, and business KPIs continuously. Instead of polling dashboards or running scheduled queries, a streaming database maintains always-current metrics as SQL materialized views — and can trigger alerts when thresholds are breached.
Monitoring Views
-- API latency monitoring
CREATE MATERIALIZED VIEW api_latency AS
SELECT endpoint,
COUNT(*) as requests_5min,
AVG(latency_ms) as avg_latency,
percentile_cont(0.99) WITHIN GROUP (ORDER BY latency_ms) as p99_latency,
COUNT(*) FILTER (WHERE status >= 500) as errors_5min
FROM api_logs WHERE ts > NOW() - INTERVAL '5 minutes'
GROUP BY endpoint;
-- SLA breach alerts
CREATE MATERIALIZED VIEW sla_alerts AS
SELECT endpoint, p99_latency, errors_5min,
errors_5min::DECIMAL / NULLIF(requests_5min, 0) as error_rate
FROM api_latency
WHERE p99_latency > 500 OR errors_5min::DECIMAL / NULLIF(requests_5min, 0) > 0.01;
Connect Grafana via PostgreSQL for live dashboards. Set up alerts on the sla_alerts view.
Replacing Prometheus + Grafana?
Not exactly. RisingWave complements Prometheus for business-level monitoring — KPIs, transaction metrics, SLA tracking — where metrics come from application events rather than infrastructure scraping.
Frequently Asked Questions
Can I use RisingWave for infrastructure monitoring?
RisingWave is best for application and business metrics from event streams. For infrastructure metrics (CPU, memory, disk), Prometheus/Datadog remain better suited. Use RisingWave for real-time business KPI dashboards.
How do I set up alerts?
Query the alert materialized view from your alerting system (PagerDuty, OpsGenie) via PostgreSQL. When rows appear in the alert view, trigger notifications.

