mirror of
https://codeberg.org/YGGverse/psocks.git
synced 2026-04-01 08:55:27 +00:00
implement uptime stats
This commit is contained in:
parent
6be42e596a
commit
29895bf35a
3 changed files with 34 additions and 5 deletions
|
|
@ -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])
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue