implement uptime stats

This commit is contained in:
postscriptum 2026-03-22 23:25:34 +02:00
parent 6be42e596a
commit 29895bf35a
3 changed files with 34 additions and 5 deletions

View file

@ -12,13 +12,13 @@ use log::*;
use opt::{AuthMode, Opt};
use rocket::{State, http::Status, serde::json::Json};
use stats::{Snap, Total};
use std::{future::Future, sync::Arc};
use std::{future::Future, sync::Arc, time::Instant};
use structopt::StructOpt;
use tokio::{net::TcpListener, task};
#[rocket::get("/")]
async fn index(totals: &State<Arc<Total>>) -> Json<Snap> {
Json(totals.inner().snap())
async fn index(totals: &State<Arc<Total>>, startup_time: &State<Instant>) -> Json<Snap> {
Json(totals.inner().snap(startup_time.elapsed().as_secs()))
}
#[rocket::get("/allow/<rule>")]
@ -83,6 +83,7 @@ async fn rocket() -> _ {
})
.manage(list)
.manage(totals)
.manage(Instant::now())
.mount("/", rocket::routes![index, allow, block])
}