diff --git a/src/blog.rs b/src/blog.rs index fa448aa6329286c30c2da908633993f11c6cc770..fed1c0e7ac4e3c1eca3b227e3a2e4896b4c5abcd 100644 --- a/src/blog.rs +++ b/src/blog.rs @@ -5,8 +5,8 @@ use fnv::FnvHashMap; use warp::hyper::StatusCode; use crate::{ - config::Config, favicon::Favicon, image::MyImage, load::load_from_path, misc::Misc, - path::UrlPath, post::Post, resp::Response, style::Style, + config::Config, favicon::Favicon, image::MyImage, load::load_from_path, metrics::HTTP_COUNTER, + misc::Misc, path::UrlPath, post::Post, resp::Response, style::Style, }; pub struct Blog { @@ -118,10 +118,16 @@ pub struct RenderedBlog { impl RenderedBlog { pub fn get(&self, path: &UrlPath) -> (StatusCode, Response) { - self.pages - .get(path) - .map(|x| (StatusCode::OK, x.clone())) - .unwrap_or((StatusCode::NOT_FOUND, self.not_found.clone())) + match self.pages.get(path) { + Some(x) => { + HTTP_COUNTER.with_label_values(&[&path.to_string()]).inc(); + (StatusCode::OK, x.clone()) + } + None => { + HTTP_COUNTER.with_label_values(&["unknown"]).inc(); + (StatusCode::NOT_FOUND, self.not_found.clone()) + } + } } } diff --git a/src/main.rs b/src/main.rs index 9b77da40c7a3393a4c561973237dbdbefc98ffcf..f4c481e4fbfa1d73be1e6b95cbb59c2aefc8a193 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,7 @@ use blog::{Blog, RenderedBlog}; use config::Config; use metrics::{ - BUILD_BLOG_FROM_ASSETS, HTTP_COUNTER, INVALID_EXPIRES_HEADER_VALUE, REQUEST_LATENCY, - RESPONSE_COUNTER, + BUILD_BLOG_FROM_ASSETS, INVALID_EXPIRES_HEADER_VALUE, REQUEST_LATENCY, RESPONSE_COUNTER, }; use path::UrlPath; use std::sync::Arc; @@ -39,7 +38,6 @@ async fn handle_request( let timer = REQUEST_LATENCY.start_timer(); let path = UrlPath::new(req.as_str()); - HTTP_COUNTER.with_label_values(&[&path.to_string()]).inc(); let blog = blog.read().await; let (status, content) = blog.get(&path);