use std::collections::HashMap;
pub struct PrometheusExporter;
pub struct GrafanaExporter;
pub struct DataDogExporter;
impl PrometheusExporter {
pub async fn export(&self, metrics: HashMap<String, f64>) -> String {
let mut output = String::new();
for (name, value) in metrics {
output.push_str(&format!(
"# HELP {} Authentication framework metric\n",
name
));
output.push_str(&format!("# TYPE {} gauge\n", name));
output.push_str(&format!("{} {}\n", name, value));
}
output
}
}
impl GrafanaExporter {
pub async fn export(&self, metrics: HashMap<String, f64>) -> serde_json::Value {
serde_json::json!({
"dashboard": "auth-framework",
"metrics": metrics,
"timestamp": chrono::Utc::now().timestamp()
})
}
}
impl DataDogExporter {
pub async fn export(&self, metrics: HashMap<String, f64>) -> Vec<serde_json::Value> {
let timestamp = chrono::Utc::now().timestamp();
metrics
.into_iter()
.map(|(name, value)| {
serde_json::json!({
"metric": name,
"points": [[timestamp, value]],
"type": "gauge",
"host": "auth-framework",
"tags": ["component:auth", "service:authentication"]
})
})
.collect()
}
}