Skip to content
Snippets Groups Projects
Commit 54ee546f authored by Stephen D's avatar Stephen D
Browse files

request latency and response metrics

parent 33fd1286
No related branches found
No related tags found
No related merge requests found
use blog::{Blog, RenderedBlog};
use config::Config;
use metrics::{BUILD_BLOG_FROM_ASSETS, HTTP_COUNTER, INVALID_EXPIRES_HEADER_VALUE};
use metrics::{
BUILD_BLOG_FROM_ASSETS, HTTP_COUNTER, INVALID_EXPIRES_HEADER_VALUE, REQUEST_LATENCY,
RESPONSE_COUNTER,
};
use path::UrlPath;
use std::sync::Arc;
use tokio::sync::RwLock;
......@@ -33,6 +36,8 @@ async fn handle_request(
req: FullPath,
blog: Arc<RwLock<RenderedBlog>>,
) -> Result<impl warp::Reply, warp::Rejection> {
let timer = REQUEST_LATENCY.start_timer();
let path = UrlPath::new(req.as_str());
HTTP_COUNTER.with_label_values(&[&path.to_string()]).inc();
......@@ -55,6 +60,12 @@ async fn handle_request(
}
*reply.status_mut() = status;
RESPONSE_COUNTER
.with_label_values(&[&status.as_u16().to_string()])
.inc();
timer.observe_duration();
Ok(reply)
}
......
......@@ -23,6 +23,10 @@ lazy_static! {
vec![0.5, 1.0, 2.5, 5.0, 10.0, 25.0, 50.0, 100.0]
)
.unwrap();
pub static ref REQUEST_LATENCY: Histogram =
register_histogram!("org_request_latency_seconds", "Request latency").unwrap();
pub static ref RESPONSE_COUNTER: CounterVec =
register_counter_vec!("org_response_total", "HTTP response codes", &["code"]).unwrap();
}
#[derive(Deserialize)]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment