Skip to content

Instantly share code, notes, and snippets.

@bkeepers
Last active September 13, 2023 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkeepers/f44335bd2a65a5f47084cdad9ffa3470 to your computer and use it in GitHub Desktop.
Save bkeepers/f44335bd2a65a5f47084cdad9ffa3470 to your computer and use it in GitHub Desktop.
good_job queries to make latency/runtime graphs

Queries to show GoodJob queue latency, runtime, and counts in Blazer

IMG_6587

IMG_1893

SELECT date_trunc('hour', created_at), queue_name, count(*)
FROM "good_job_executions"
GROUP BY 1, 2
ORDER BY 1 DESC
WITH jobs AS (
SELECT
*,
ROUND(EXTRACT(epoch FROM (created_at - scheduled_at)) * 1000)::integer AS latency
FROM "good_job_executions"
)
SELECT
date_trunc('minute', created_at) as minute,
queue_name,
count(*) as jobs
FROM jobs
WHERE latency > 1000
AND created_at >= NOW() - INTERVAL '30 minutes'
GROUP BY 1, 2
ORDER BY 1
WITH jobs AS (
SELECT
created_at,
ROUND(EXTRACT(epoch FROM (created_at - scheduled_at)) * 1000)::integer AS latency
FROM "good_job_executions"
)
SELECT
date_trunc('hour', created_at),
MAX(latency) as "max",
percentile_disc(0.99) within group (order by latency) AS "99th",
percentile_disc(0.95) within group (order by latency) AS "95th",
percentile_disc(0.5) within group (order by latency) AS "50th"
FROM jobs
GROUP BY 1
ORDER BY 1 DESC
WITH jobs AS (
SELECT created_at,
ROUND(EXTRACT(epoch FROM (finished_at - created_at)) * 1000)::integer AS runtime
FROM "good_job_executions"
)
SELECT
date_trunc('hour', created_at),
MAX(runtime) as "max",
percentile_disc(0.99) within group (order by runtime) AS "99th",
percentile_disc(0.95) within group (order by runtime) AS "95th",
percentile_disc(0.5) within group (order by runtime) AS "50th"
FROM jobs
GROUP BY 1
ORDER BY 1 DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment