1use crate::server::AppState;
4use axum::{extract::State, http::StatusCode, Json};
5use otelite_core::api::ErrorResponse;
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Serialize, Deserialize, utoipa::ToSchema)]
10pub struct StatsResponse {
11 pub log_count: u64,
13 pub span_count: u64,
15 pub metric_count: u64,
17 pub storage_size_bytes: u64,
19}
20
21#[utoipa::path(
23 get,
24 path = "/api/stats",
25 responses(
26 (status = 200, description = "Storage statistics", body = StatsResponse),
27 (status = 500, description = "Internal server error", body = ErrorResponse)
28 ),
29 tag = "stats"
30)]
31pub async fn get_stats(
32 State(state): State<AppState>,
33) -> Result<Json<StatsResponse>, (StatusCode, Json<ErrorResponse>)> {
34 let storage_stats = state.storage.stats().await.map_err(|e| {
35 (
36 StatusCode::INTERNAL_SERVER_ERROR,
37 Json(ErrorResponse::storage_error(format!("get stats: {}", e))),
38 )
39 })?;
40
41 Ok(Json(StatsResponse {
42 log_count: storage_stats.log_count,
43 span_count: storage_stats.span_count,
44 metric_count: storage_stats.metric_count,
45 storage_size_bytes: storage_stats.storage_size_bytes,
46 }))
47}