MCPcopy Create free account
hub / github.com/clawshell/clawshell / handle_stats

Function handle_stats

src/app.rs:494–509  ·  view source on GitHub ↗

Management endpoint that returns running counters for total requests, upstream token usage, and per-sender email-filter activity. Only reachable from loopback peers; streaming (SSE) responses are not included in token totals (see `handle_request`).

(
    State(state): State<AppState>,
    ConnectInfo(peer): ConnectInfo<SocketAddr>,
)

Source from the content-addressed store, hash-verified

492/// reachable from loopback peers; streaming (SSE) responses are not
493/// included in token totals (see `handle_request`).
494async fn handle_stats(
495 State(state): State<AppState>,
496 ConnectInfo(peer): ConnectInfo<SocketAddr>,
497) -> Result<Response, Response> {
498 if !peer.ip().is_loopback() {
499 warn!(
500 peer = %peer,
501 "Non-loopback client tried to hit /admin/stats"
502 );
503 return Err(error_response(
504 StatusCode::FORBIDDEN,
505 "stats endpoint is loopback-only",
506 ));
507 }
508 Ok(axum::Json(state.stats.snapshot()).into_response())
509}
510
511async fn handle_request(
512 State(state): State<AppState>,

Callers

nothing calls this directly

Calls 3

error_responseFunction · 0.85
into_responseMethod · 0.80
snapshotMethod · 0.80

Tested by

no test coverage detected