risedev/config_gen/
prometheus_gen.rs1use chrono::prelude::*;
16use itertools::Itertools;
17
18use crate::PrometheusConfig;
19
20pub struct PrometheusGen;
21
22impl PrometheusGen {
23 pub fn gen_prometheus_yml(&self, config: &PrometheusConfig) -> String {
24 let prometheus_host = &config.address;
25 let prometheus_port = &config.port;
26 let scrape_interval = &config.scrape_interval;
27 let compute_node_targets = config
28 .provide_compute_node
29 .as_ref()
30 .unwrap()
31 .iter()
32 .map(|node| format!("\"{}:{}\"", node.address, node.exporter_port))
33 .join(",");
34
35 let frontend_targets = config
36 .provide_frontend
37 .as_ref()
38 .unwrap()
39 .iter()
40 .map(|node| format!("\"{}:{}\"", node.address, node.exporter_port))
41 .join(",");
42
43 let meta_node_targets = config
44 .provide_meta_node
45 .as_ref()
46 .unwrap()
47 .iter()
48 .map(|node| format!("\"{}:{}\"", node.address, node.exporter_port))
49 .join(",");
50
51 let minio_targets = config
52 .provide_minio
53 .as_ref()
54 .unwrap()
55 .iter()
56 .map(|node| format!("\"{}:{}\"", node.address, node.port))
57 .join(",");
58
59 let compactor_targets = config
60 .provide_compactor
61 .as_ref()
62 .unwrap()
63 .iter()
64 .map(|node| format!("\"{}:{}\"", node.address, node.exporter_port))
65 .join(",");
66
67 let redpanda_targets = config
68 .provide_redpanda
69 .as_ref()
70 .unwrap()
71 .iter()
72 .map(|node| format!("\"{}:{}\"", node.address, 9644))
73 .join(",");
74
75 let now = Local::now().format("%Y%m%d-%H%M%S");
76
77 let remote_write = if config.remote_write {
78 let remote_write_region = &config.remote_write_region;
79 let remote_write_url = &config.remote_write_url;
80 format!(
81 r#"
82remote_write:
83 -
84 url: {remote_write_url}
85 queue_config:
86 max_samples_per_send: 1000
87 max_shards: 200
88 capacity: 2500
89 sigv4:
90 region: {remote_write_region}
91"#,
92 )
93 } else {
94 String::from("")
95 };
96
97 format!(
98 r#"# --- THIS FILE IS AUTO GENERATED BY RISEDEV ---
99global:
100 scrape_interval: {scrape_interval}
101 evaluation_interval: 60s
102 external_labels:
103 rw_cluster: {now}
104{remote_write}
105
106scrape_configs:
107 - job_name: prometheus
108 static_configs:
109 - targets: ["{prometheus_host}:{prometheus_port}"]
110
111 - job_name: compute
112 static_configs:
113 - targets: [{compute_node_targets}]
114
115 - job_name: meta
116 static_configs:
117 - targets: [{meta_node_targets}]
118
119 - job_name: minio
120 metrics_path: /minio/v2/metrics/cluster
121 static_configs:
122 - targets: [{minio_targets}]
123
124 - job_name: compactor
125 static_configs:
126 - targets: [{compactor_targets}]
127
128 - job_name: frontend
129 static_configs:
130 - targets: [{frontend_targets}]
131
132 - job_name: redpanda
133 static_configs:
134 - targets: [{redpanda_targets}]
135"#,
136 )
137 }
138}