remove old global stats api

This commit is contained in:
4cuck committed 2025-05-16 19:54:06 +02:00
1 parent 60f3548842
commit 8734452f19
2 files changed
-82

No files matched your search

-80
View File
@@ -34,83 +34,3 @@ pub async fn instances(
);
Ok(res)
}
pub async fn graph_csv_health(
State(ref db): State<DatabaseConnection>,
State(ref config): State<Arc<crate::Config>>,
) -> Result<axum::response::Response> {
let start = std::time::Instant::now();
let healthy_data = health_check::HealthyAmount::fetch(db, None, None, None).await?;
let queried = std::time::Instant::now();
let mut data = String::with_capacity(8 * healthy_data.len());
data.push_str("Date,Healthy,Dead\n");
for entry in healthy_data {
let time = Utc
.timestamp_opt(entry.time, 0)
.unwrap()
.format("%Y-%m-%dT%H:%M:%SZ");
writeln!(&mut data, "{time},{},{}", entry.alive, entry.dead)
.map_err(|e| ServerError::CSV(e.to_string()))?;
}
let formatted = std::time::Instant::now();
let query_time = queried - start;
let format_time = formatted - queried;
tracing::debug!(?query_time, ?format_time);
let mut res = data.into_response();
res.headers_mut()
.insert("content-type", HeaderValue::from_str("text/csv").unwrap());
res.headers_mut().insert(
"cache-control",
HeaderValue::from_str(&format!("public, max-age={}", config.max_age)).unwrap(),
);
res.headers_mut().insert(
"X-Robots-Tag",
HeaderValue::from_static("noindex, nofollow"),
);
Ok(res)
}
pub async fn graph_csv_stats(
State(ref db): State<DatabaseConnection>,
State(ref config): State<Arc<crate::Config>>,
) -> Result<axum::response::Response> {
let start = std::time::Instant::now();
let healthy_data = instance_stats::StatsCSVEntry::fetch(db, None).await?;
let queried = std::time::Instant::now();
let mut data = String::with_capacity(8 * healthy_data.len());
data.push_str("Date,Tokens AVG,Limited Tokens AVG,Requests AVG\n");
for entry in healthy_data {
let time = Utc
.timestamp_opt(entry.time, 0)
.unwrap()
.format("%Y-%m-%dT%H:%M:%SZ");
writeln!(
&mut data,
"{time},{},{},{}",
entry.total_accs_avg, entry.limited_accs_avg, entry.total_requests_avg
)
.map_err(|e| ServerError::CSV(e.to_string()))?;
}
let formatted = std::time::Instant::now();
let query_time = queried - start;
let format_time = formatted - queried;
tracing::debug!(?query_time, ?format_time);
let mut res = data.into_response();
res.headers_mut()
.insert("content-type", HeaderValue::from_str("text/csv").unwrap());
res.headers_mut().insert(
"cache-control",
HeaderValue::from_str(&format!("public, max-age={}", config.max_age)).unwrap(),
);
res.headers_mut().insert(
"X-Robots-Tag",
HeaderValue::from_static("noindex, nofollow"),
);
Ok(res)
}
-2
View File
@@ -148,8 +148,6 @@ pub async fn start(
ServeDir::new("server/static").append_index_html_on_directories(false),
)
.route("/api/v1/instances", get(api::instances))
.route("/api/csv/health", get(api::graph_csv_health))
.route("/api/csv/stats", get(api::graph_csv_stats))
.nest(ADMIN_OVERVIEW_URL, Router::new()
.route("/", get(admin::overview))
.route("/instance/errors/:instance", get(admin::errors_view))