forked from ArroyoSystems/arroyo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_optimized_prometheus_config.sql
More file actions
78 lines (69 loc) · 2.02 KB
/
example_optimized_prometheus_config.sql
File metadata and controls
78 lines (69 loc) · 2.02 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
73
74
75
76
77
78
-- Example configuration for Prometheus Remote Write Optimized Source
-- This is for your workload: 80K unique time series with 5 labels
-- Create the optimized Prometheus source table
CREATE TABLE prometheus_metrics (
-- Fixed columns (always present)
metric_name TEXT,
timestamp TIMESTAMP, -- Prometheus timestamp in milliseconds
value DOUBLE, -- Metric value
-- Label columns (flattened for performance)
-- ORDER MATTERS: Must match the order in label_names array
instance TEXT,
job TEXT,
label1 TEXT,
label2 TEXT,
label3 TEXT,
-- System timestamp (ingestion time in nanoseconds)
_timestamp TIMESTAMP
) WITH (
connector = 'prometheus_remote_write_optimized',
base_port = '9090',
path = '/receive',
bind_address = '0.0.0.0',
-- CRITICAL: This defines which labels to extract as columns
-- Must match the order of label columns above
label_names = '["instance", "job", "label1", "label2", "label3"]'
);
-- Example queries you can run
-- 1. Get all metrics for a specific instance
SELECT * FROM prometheus_metrics
WHERE instance = 'my-instance-name'
LIMIT 100;
-- 2. Aggregate by instance over 1-minute windows
SELECT
instance,
AVG(value) as avg_value,
MIN(value) as min_value,
MAX(value) as max_value,
COUNT(*) as count,
TUMBLE_START(INTERVAL '1' MINUTE) as window_start
FROM prometheus_metrics
WHERE metric_name = 'your_metric_name'
GROUP BY
instance,
TUMBLE(INTERVAL '1' MINUTE);
-- 3. Filter by multiple labels (very fast with flattened schema)
SELECT
instance,
label1,
label2,
value,
timestamp
FROM prometheus_metrics
WHERE label1 = 'some_value'
AND label2 = 'other_value'
AND instance LIKE 'server%';
-- 4. Real-time aggregation by all label dimensions
SELECT
label1,
label2,
label3,
COUNT(*) as metric_count,
AVG(value) as avg_value,
TUMBLE_START(INTERVAL '10' SECOND) as window_start
FROM prometheus_metrics
GROUP BY
label1,
label2,
label3,
TUMBLE(INTERVAL '10' SECOND);