auth_framework/monitoring/
exporters.rs1use std::collections::HashMap;
4
5pub struct PrometheusExporter;
7
8pub struct GrafanaExporter;
10
11pub struct DataDogExporter;
13
14impl PrometheusExporter {
15 pub async fn export(&self, metrics: HashMap<String, f64>) -> String {
17 let mut output = String::new();
19
20 for (name, value) in metrics {
21 output.push_str(&format!(
22 "# HELP {} Authentication framework metric\n",
23 name
24 ));
25 output.push_str(&format!("# TYPE {} gauge\n", name));
26 output.push_str(&format!("{} {}\n", name, value));
27 }
28
29 output
30 }
31}
32
33impl GrafanaExporter {
34 pub async fn export(&self, metrics: HashMap<String, f64>) -> serde_json::Value {
36 serde_json::json!({
38 "dashboard": "auth-framework",
39 "metrics": metrics,
40 "timestamp": chrono::Utc::now().timestamp()
41 })
42 }
43}
44
45impl DataDogExporter {
46 pub async fn export(&self, metrics: HashMap<String, f64>) -> Vec<serde_json::Value> {
48 let timestamp = chrono::Utc::now().timestamp();
50
51 metrics
52 .into_iter()
53 .map(|(name, value)| {
54 serde_json::json!({
55 "metric": name,
56 "points": [[timestamp, value]],
57 "type": "gauge",
58 "host": "auth-framework",
59 "tags": ["component:auth", "service:authentication"]
60 })
61 })
62 .collect()
63 }
64}
65
66