\pset pager off
WITH w AS (SELECT * FROM ops_error_logs WHERE created_at >= now() - interval '5 minutes')
SELECT 'last5m_total' k, count(*)::text v FROM w;
WITH w AS (SELECT * FROM ops_error_logs WHERE created_at >= now() - interval '5 minutes')
SELECT COALESCE(group_id,0) group_id, COALESCE(account_id,0) account_id, model, COALESCE(status_code,0) status_code, COALESCE(upstream_status_code,0) upstream_status_code, left(error_message,120) msg, count(*)
FROM w
WHERE account_id IS NOT NULL OR error_message ILIKE '%no available%' OR status_code >= 500 OR upstream_status_code >= 500 OR upstream_status_code=429
GROUP BY 1,2,3,4,5,6 ORDER BY count(*) DESC LIMIT 20;
