Add request stats to instance info page
This commit is contained in:
parent
193a6effbf
commit
de68409610
@ -10,6 +10,7 @@ use serde_json::Value;
|
||||
use std::{io, result::Result};
|
||||
|
||||
use crate::dbg_msg;
|
||||
use crate::instance_info::INSTANCE_INFO;
|
||||
use crate::server::RequestExt;
|
||||
|
||||
const REDDIT_URL_BASE: &str = "https://www.reddit.com";
|
||||
@ -125,6 +126,9 @@ fn reddit_head(path: String, quarantine: bool) -> Boxed<Result<Response<Body>, S
|
||||
/// will recurse on the URL that Reddit provides in the Location HTTP header
|
||||
/// in its response.
|
||||
fn request(method: &'static Method, path: String, redirect: bool, quarantine: bool) -> Boxed<Result<Response<Body>, String>> {
|
||||
// Increment reddit request count. This will include head requests.
|
||||
INSTANCE_INFO.reddit_requests.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
||||
|
||||
// Build Reddit URL from path.
|
||||
let url = format!("{}{}", REDDIT_URL_BASE, path);
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::sync::atomic::AtomicU32;
|
||||
|
||||
use crate::{
|
||||
config::{Config, CONFIG},
|
||||
server::RequestExt,
|
||||
@ -88,6 +90,8 @@ pub(crate) struct InstanceInfo {
|
||||
deploy_date: String,
|
||||
compile_mode: String,
|
||||
deploy_unix_ts: i64,
|
||||
pub(crate) reddit_requests: AtomicU32,
|
||||
pub(crate) total_requests: AtomicU32,
|
||||
config: Config,
|
||||
}
|
||||
|
||||
@ -103,6 +107,8 @@ impl InstanceInfo {
|
||||
compile_mode: "Release".into(),
|
||||
deploy_unix_ts: OffsetDateTime::now_local().unwrap_or_else(|_| OffsetDateTime::now_utc()).unix_timestamp(),
|
||||
config: CONFIG.clone(),
|
||||
reddit_requests: AtomicU32::new(0),
|
||||
total_requests: AtomicU32::new(0),
|
||||
}
|
||||
}
|
||||
fn to_table(&self) -> String {
|
||||
|
@ -23,7 +23,7 @@ use std::{
|
||||
};
|
||||
use time::Duration;
|
||||
|
||||
use crate::dbg_msg;
|
||||
use crate::{dbg_msg, instance_info::INSTANCE_INFO};
|
||||
|
||||
type BoxResponse = Pin<Box<dyn Future<Output = Result<Response<Body>, String>> + Send>>;
|
||||
|
||||
@ -234,6 +234,8 @@ impl Server {
|
||||
match router.recognize(&format!("/{}{}", req.method().as_str(), path)) {
|
||||
// If a route was configured for this path
|
||||
Ok(found) => {
|
||||
// Add to total_requests count
|
||||
INSTANCE_INFO.total_requests.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
||||
let mut parammed = req;
|
||||
parammed.set_params(found.params().clone());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user