1pub const LABEL_PROTOCOL: &str = "protocol";
26
27pub const LABEL_SEVERITY: &str = "severity";
29
30pub const LABEL_MODULE: &str = "module";
32
33pub const LABEL_PARSER_FORMAT: &str = "format";
35
36pub const LABEL_ACTION: &str = "action";
38
39pub const LABEL_ECOSYSTEM: &str = "ecosystem";
41
42pub const LABEL_RESULT: &str = "result";
44
45pub const EBPF_PACKETS_TOTAL: &str = "ironpost_ebpf_packets_total";
49
50pub const EBPF_PACKETS_BLOCKED_TOTAL: &str = "ironpost_ebpf_packets_blocked_total";
52
53pub const EBPF_BYTES_TOTAL: &str = "ironpost_ebpf_bytes_total";
55
56pub const EBPF_XDP_PROCESSING_DURATION_SECONDS: &str =
58 "ironpost_ebpf_xdp_processing_duration_seconds";
59
60pub const EBPF_PROTOCOL_PACKETS_TOTAL: &str = "ironpost_ebpf_protocol_packets_total";
62
63pub const EBPF_PACKETS_PER_SECOND: &str = "ironpost_ebpf_packets_per_second";
65
66pub const EBPF_BITS_PER_SECOND: &str = "ironpost_ebpf_bits_per_second";
68
69pub const LOG_PIPELINE_LOGS_COLLECTED_TOTAL: &str = "ironpost_log_pipeline_logs_collected_total";
73
74pub const LOG_PIPELINE_LOGS_PROCESSED_TOTAL: &str = "ironpost_log_pipeline_logs_processed_total";
76
77pub const LOG_PIPELINE_PARSE_ERRORS_TOTAL: &str = "ironpost_log_pipeline_parse_errors_total";
79
80pub const LOG_PIPELINE_RULE_MATCHES_TOTAL: &str = "ironpost_log_pipeline_rule_matches_total";
82
83pub const LOG_PIPELINE_ALERTS_SENT_TOTAL: &str = "ironpost_log_pipeline_alerts_sent_total";
85
86pub const LOG_PIPELINE_PROCESSING_DURATION_SECONDS: &str =
88 "ironpost_log_pipeline_processing_duration_seconds";
89
90pub const LOG_PIPELINE_BUFFER_SIZE: &str = "ironpost_log_pipeline_buffer_size";
92
93pub const LOG_PIPELINE_LOGS_DROPPED_TOTAL: &str = "ironpost_log_pipeline_logs_dropped_total";
95
96pub const CONTAINER_GUARD_MONITORED_CONTAINERS: &str =
100 "ironpost_container_guard_monitored_containers";
101
102pub const CONTAINER_GUARD_POLICY_VIOLATIONS_TOTAL: &str =
104 "ironpost_container_guard_policy_violations_total";
105
106pub const CONTAINER_GUARD_ISOLATIONS_TOTAL: &str = "ironpost_container_guard_isolations_total";
108
109pub const CONTAINER_GUARD_ISOLATION_FAILURES_TOTAL: &str =
111 "ironpost_container_guard_isolation_failures_total";
112
113pub const CONTAINER_GUARD_ALERTS_PROCESSED_TOTAL: &str =
115 "ironpost_container_guard_alerts_processed_total";
116
117pub const CONTAINER_GUARD_POLICIES_LOADED: &str = "ironpost_container_guard_policies_loaded";
119
120pub const SBOM_SCANNER_SCANS_COMPLETED_TOTAL: &str = "ironpost_sbom_scanner_scans_completed_total";
124
125pub const SBOM_SCANNER_CVES_FOUND: &str = "ironpost_sbom_scanner_cves_found";
127
128pub const SBOM_SCANNER_SCAN_DURATION_SECONDS: &str = "ironpost_sbom_scanner_scan_duration_seconds";
130
131pub const SBOM_SCANNER_PACKAGES_SCANNED_TOTAL: &str =
133 "ironpost_sbom_scanner_packages_scanned_total";
134
135pub const SBOM_SCANNER_VULNDB_LAST_UPDATE: &str =
137 "ironpost_sbom_scanner_vulndb_last_update_timestamp";
138
139pub const DAEMON_UPTIME_SECONDS: &str = "ironpost_daemon_uptime_seconds";
143
144pub const DAEMON_PLUGINS_REGISTERED: &str = "ironpost_daemon_plugins_registered";
146
147pub const DAEMON_BUILD_INFO: &str = "ironpost_daemon_build_info";
149
150pub const PROCESSING_DURATION_BUCKETS: [f64; 10] = [
156 0.0001, 0.0005, 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1.0, 10.0,
157];
158
159pub const SCAN_DURATION_BUCKETS: [f64; 9] = [0.1, 0.5, 1.0, 5.0, 10.0, 30.0, 60.0, 120.0, 300.0];
163
164pub fn describe_all() {
174 use metrics::{describe_counter, describe_gauge, describe_histogram};
175
176 describe_counter!(
178 EBPF_PACKETS_TOTAL,
179 "Total number of packets processed by eBPF XDP"
180 );
181 describe_counter!(
182 EBPF_PACKETS_BLOCKED_TOTAL,
183 "Total number of packets blocked (XDP_DROP) by eBPF"
184 );
185 describe_counter!(EBPF_BYTES_TOTAL, "Total bytes processed by eBPF XDP");
186 describe_histogram!(
187 EBPF_XDP_PROCESSING_DURATION_SECONDS,
188 "XDP packet processing latency in seconds"
189 );
190 describe_counter!(
191 EBPF_PROTOCOL_PACKETS_TOTAL,
192 "Packets processed per protocol (TCP, UDP, ICMP, other)"
193 );
194 describe_gauge!(
195 EBPF_PACKETS_PER_SECOND,
196 "Current packet processing rate (packets/sec)"
197 );
198 describe_gauge!(EBPF_BITS_PER_SECOND, "Current throughput rate (bits/sec)");
199
200 describe_counter!(
202 LOG_PIPELINE_LOGS_COLLECTED_TOTAL,
203 "Total number of raw log lines collected from all sources"
204 );
205 describe_counter!(
206 LOG_PIPELINE_LOGS_PROCESSED_TOTAL,
207 "Total number of log entries successfully parsed and processed"
208 );
209 describe_counter!(
210 LOG_PIPELINE_PARSE_ERRORS_TOTAL,
211 "Total number of log parsing failures"
212 );
213 describe_counter!(
214 LOG_PIPELINE_RULE_MATCHES_TOTAL,
215 "Total number of detection rule matches"
216 );
217 describe_counter!(
218 LOG_PIPELINE_ALERTS_SENT_TOTAL,
219 "Total number of alert events sent to downstream consumers"
220 );
221 describe_histogram!(
222 LOG_PIPELINE_PROCESSING_DURATION_SECONDS,
223 "Time to process a single log batch in seconds"
224 );
225 describe_gauge!(
226 LOG_PIPELINE_BUFFER_SIZE,
227 "Current number of log entries in the processing buffer"
228 );
229 describe_counter!(
230 LOG_PIPELINE_LOGS_DROPPED_TOTAL,
231 "Total number of log entries dropped due to buffer overflow"
232 );
233
234 describe_gauge!(
236 CONTAINER_GUARD_MONITORED_CONTAINERS,
237 "Number of containers currently being monitored"
238 );
239 describe_counter!(
240 CONTAINER_GUARD_POLICY_VIOLATIONS_TOTAL,
241 "Total number of security policy violations detected"
242 );
243 describe_counter!(
244 CONTAINER_GUARD_ISOLATIONS_TOTAL,
245 "Total number of container isolation actions executed"
246 );
247 describe_counter!(
248 CONTAINER_GUARD_ISOLATION_FAILURES_TOTAL,
249 "Total number of failed container isolation attempts"
250 );
251 describe_counter!(
252 CONTAINER_GUARD_ALERTS_PROCESSED_TOTAL,
253 "Total number of alert events processed by container guard"
254 );
255 describe_gauge!(
256 CONTAINER_GUARD_POLICIES_LOADED,
257 "Number of security policies currently loaded"
258 );
259
260 describe_counter!(
262 SBOM_SCANNER_SCANS_COMPLETED_TOTAL,
263 "Total number of SBOM scans completed"
264 );
265 describe_gauge!(
266 SBOM_SCANNER_CVES_FOUND,
267 "Number of CVEs found by severity level"
268 );
269 describe_histogram!(
270 SBOM_SCANNER_SCAN_DURATION_SECONDS,
271 "Time to complete a single SBOM scan in seconds"
272 );
273 describe_counter!(
274 SBOM_SCANNER_PACKAGES_SCANNED_TOTAL,
275 "Total number of packages scanned across all SBOM scans"
276 );
277 describe_gauge!(
278 SBOM_SCANNER_VULNDB_LAST_UPDATE,
279 "Unix timestamp of the last vulnerability database update"
280 );
281
282 describe_gauge!(DAEMON_UPTIME_SECONDS, "Ironpost daemon uptime in seconds");
284 describe_gauge!(
285 DAEMON_PLUGINS_REGISTERED,
286 "Number of plugins registered in the daemon"
287 );
288 describe_gauge!(
289 DAEMON_BUILD_INFO,
290 "Build information (always 1, with version/commit labels)"
291 );
292}
293
294#[cfg(test)]
295mod tests {
296 use super::*;
297
298 const ALL_METRIC_NAMES: &[&str] = &[
300 EBPF_PACKETS_TOTAL,
301 EBPF_PACKETS_BLOCKED_TOTAL,
302 EBPF_BYTES_TOTAL,
303 EBPF_XDP_PROCESSING_DURATION_SECONDS,
304 EBPF_PROTOCOL_PACKETS_TOTAL,
305 EBPF_PACKETS_PER_SECOND,
306 EBPF_BITS_PER_SECOND,
307 LOG_PIPELINE_LOGS_COLLECTED_TOTAL,
308 LOG_PIPELINE_LOGS_PROCESSED_TOTAL,
309 LOG_PIPELINE_PARSE_ERRORS_TOTAL,
310 LOG_PIPELINE_RULE_MATCHES_TOTAL,
311 LOG_PIPELINE_ALERTS_SENT_TOTAL,
312 LOG_PIPELINE_PROCESSING_DURATION_SECONDS,
313 LOG_PIPELINE_BUFFER_SIZE,
314 LOG_PIPELINE_LOGS_DROPPED_TOTAL,
315 CONTAINER_GUARD_MONITORED_CONTAINERS,
316 CONTAINER_GUARD_POLICY_VIOLATIONS_TOTAL,
317 CONTAINER_GUARD_ISOLATIONS_TOTAL,
318 CONTAINER_GUARD_ISOLATION_FAILURES_TOTAL,
319 CONTAINER_GUARD_ALERTS_PROCESSED_TOTAL,
320 CONTAINER_GUARD_POLICIES_LOADED,
321 SBOM_SCANNER_SCANS_COMPLETED_TOTAL,
322 SBOM_SCANNER_CVES_FOUND,
323 SBOM_SCANNER_SCAN_DURATION_SECONDS,
324 SBOM_SCANNER_PACKAGES_SCANNED_TOTAL,
325 SBOM_SCANNER_VULNDB_LAST_UPDATE,
326 DAEMON_UPTIME_SECONDS,
327 DAEMON_PLUGINS_REGISTERED,
328 DAEMON_BUILD_INFO,
329 ];
330
331 #[test]
332 fn all_metrics_start_with_ironpost_prefix() {
333 for name in ALL_METRIC_NAMES {
334 assert!(
335 name.starts_with("ironpost_"),
336 "Metric '{}' does not start with 'ironpost_' prefix",
337 name
338 );
339 }
340 }
341
342 #[test]
343 fn all_metrics_have_29_entries() {
344 assert_eq!(
347 ALL_METRIC_NAMES.len(),
348 29,
349 "Expected 29 metrics (7 eBPF + 8 Log Pipeline + 6 Container Guard + 5 SBOM + 3 Daemon)"
350 );
351 }
352
353 #[test]
354 fn describe_all_does_not_panic() {
355 describe_all();
357 }
358
359 #[test]
360 fn label_keys_are_lowercase() {
361 let labels = [
362 LABEL_PROTOCOL,
363 LABEL_SEVERITY,
364 LABEL_MODULE,
365 LABEL_PARSER_FORMAT,
366 LABEL_ACTION,
367 LABEL_ECOSYSTEM,
368 LABEL_RESULT,
369 ];
370 for label in &labels {
371 assert_eq!(
372 label.to_lowercase(),
373 *label,
374 "Label key '{}' should be lowercase",
375 label
376 );
377 }
378 }
379
380 #[test]
381 fn processing_duration_buckets_are_sorted() {
382 let buckets = PROCESSING_DURATION_BUCKETS;
383 for i in 1..buckets.len() {
384 assert!(
385 buckets[i] > buckets[i - 1],
386 "Bucket values must be in ascending order"
387 );
388 }
389 }
390
391 #[test]
392 fn scan_duration_buckets_are_sorted() {
393 let buckets = SCAN_DURATION_BUCKETS;
394 for i in 1..buckets.len() {
395 assert!(
396 buckets[i] > buckets[i - 1],
397 "Bucket values must be in ascending order"
398 );
399 }
400 }
401}