Skip to content

Instantly share code, notes, and snippets.

@pastuhov
Created June 8, 2021 05:58
Show Gist options
  • Save pastuhov/f8eab084498a2707065d3b8216075f55 to your computer and use it in GitHub Desktop.
Save pastuhov/f8eab084498a2707065d3b8216075f55 to your computer and use it in GitHub Desktop.
Sentry db query - issues
SET TIME ZONE 5;
SELECT
error_count,
date_added,
error_count - lag(error_count, 1)
OVER () delta,
avg(error_count)
OVER () average_count,
CASE WHEN error_count > avg(error_count) OVER ()
THEN 'BAD'
ELSE '' END
FROM (
SELECT
count(id) error_count,
date_trunc('hour', date_added) AS date_added
FROM sentry_eventmapping
WHERE project_id = 28 AND date_added >= NOW() + INTERVAL '-24 hour'
GROUP BY date_trunc('hour', date_added)
ORDER BY date_trunc('hour', date_added)
) AS event
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment