Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.

Commit

Permalink
feat(schema/query): add prometheus lag and sample rate
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Dec 6, 2019
1 parent eac0341 commit 3c8d205
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
32 changes: 32 additions & 0 deletions schema/query/alert/prometheus-lag.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
SELECT
metrics.labels->>'pod' AS "metric",
MAX("time") AS "time",
EXTRACT(EPOCH FROM NOW()) - MAX(value) AS "value"
FROM metrics
WHERE
time > NOW() - INTERVAL '15 minute' AND
name = 'prometheus_remote_storage_highest_timestamp_in_seconds' AND
value != 'NaN'
GROUP BY metric
ORDER BY time DESC
LIMIT 4;


SELECT
MAX(pod) AS "metric",
"time",
MAX("local") - MAX("remote") AS "value"
FROM (
SELECT
metrics.labels->>'pod' AS "pod",
$__timeGroup("time", $__interval),
CASE WHEN name = 'prometheus_remote_storage_highest_timestamp_in_seconds' THEN value ELSE NULL END AS "local",
CASE WHEN name = 'prometheus_remote_storage_queue_highest_sent_timestamp_seconds' THEN value ELSE NULL END AS "remote"
FROM metrics
WHERE
$__timeFilter("time")
AND name IN ('prometheus_remote_storage_highest_timestamp_in_seconds', 'prometheus_remote_storage_queue_highest_sent_timestamp_seconds')
AND value != 'NaN'
) AS t
GROUP BY time, pod
ORDER BY time, pod;
51 changes: 51 additions & 0 deletions schema/query/alert/prometheus-samples.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
SELECT
bucket AS "time",
metric,
((
CASE
WHEN lag(value) OVER w IS NULL THEN 0
WHEN value > lag(value) OVER w THEN (value - lag(value) OVER w)
ELSE value
END
) / EXTRACT(EPOCH FROM INTERVAL '$__interval')) AS "value"
FROM (
SELECT
labels->>'pod' AS "metric",
time_bucket('$__interval', "time") AS "bucket",
MAX(value) AS "value"
FROM metrics
WHERE
$__timeFilter("time") and
name = 'prometheus_remote_storage_succeeded_samples_total'
GROUP BY metric, bucket
ORDER BY metric, bucket
) AS m
WHERE value > 0
WINDOW w AS (PARTITION BY metric ORDER BY bucket)
ORDER BY time;

SELECT
bucket AS "time",
metric,
((
CASE
WHEN lag(value) OVER w IS NULL THEN 0
WHEN value > lag(value) OVER w THEN (value - lag(value) OVER w)
ELSE value
END
) / EXTRACT(EPOCH FROM INTERVAL '$__interval')) AS "value"
FROM (
SELECT
labels->>'pod' AS "metric",
time_bucket('$__interval', "time") AS "bucket",
MAX(value) AS "value"
FROM metrics
WHERE
$__timeFilter("time") and
name = 'adapter_samples_sent_total'
GROUP BY metric, bucket
ORDER BY metric, bucket
) AS m
WHERE value > 0
WINDOW w AS (PARTITION BY metric ORDER BY bucket)
ORDER BY time;

0 comments on commit 3c8d205

Please sign in to comment.