forked from ArroyoSystems/arroyo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprometheus_optimized_example.sql
More file actions
72 lines (68 loc) · 1.46 KB
/
prometheus_optimized_example.sql
File metadata and controls
72 lines (68 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
-- SQL queries to use with the prometheus_optimized_source
-- (after creating the source via the JSON API config)
-- Example 1: Simple aggregation over tumbling windows
CREATE TABLE prometheus_agg AS
SELECT
instance,
job,
label1,
label2,
label3,
SUM(value) as total_value,
AVG(value) as avg_value,
COUNT(*) as metric_count
FROM prometheus_optimized_source
WHERE metric_name = 'your_metric_name'
GROUP BY
TUMBLE(INTERVAL '10' SECONDS),
instance,
job,
label1,
label2,
label3;
-- Example 2: Filter by specific labels and aggregate
CREATE TABLE filtered_metrics AS
SELECT
label1,
label2,
SUM(value) as sums,
AVG(value) as avgs,
MAX(value) as maxs,
MIN(value) as mins
FROM prometheus_optimized_source
WHERE
instance LIKE 'server%'
AND job = 'my_job'
AND metric_name = 'http_requests_total'
GROUP BY
TUMBLE(INTERVAL '5' SECONDS),
label1,
label2;
-- Example 3: Real-time monitoring - detect high values
CREATE TABLE alerts AS
SELECT
metric_name,
instance,
job,
value,
timestamp
FROM prometheus_optimized_source
WHERE value > 1000 -- Alert threshold
AND metric_name = 'cpu_usage';
-- Example 4: Group by all label dimensions
SELECT
instance,
job,
label1,
label2,
label3,
COUNT(*) as count,
SUM(value) as total
FROM prometheus_optimized_source
GROUP BY
TUMBLE(INTERVAL '1' MINUTE),
instance,
job,
label1,
label2,
label3;