Move postman and web inside src
This commit is contained in:
27
src/web/metrics.rs
Normal file
27
src/web/metrics.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use rocket::{
|
||||
fairing::{Fairing, Info, Kind},
|
||||
Request, Response,
|
||||
};
|
||||
|
||||
use crate::metrics::REQUEST_COUNTER;
|
||||
|
||||
pub struct MetricProducer;
|
||||
|
||||
#[rocket::async_trait]
|
||||
impl Fairing for MetricProducer {
|
||||
fn info(&self) -> Info {
|
||||
Info { name: "Metrics fairing", kind: Kind::Response }
|
||||
}
|
||||
|
||||
async fn on_response<'r>(&self, req: &'r Request<'_>, resp: &mut Response<'r>) {
|
||||
if let Some(route) = req.route() {
|
||||
REQUEST_COUNTER
|
||||
.with_label_values(&[
|
||||
req.method().as_str(),
|
||||
&resp.status().code.to_string(),
|
||||
&route.uri.to_string(),
|
||||
])
|
||||
.inc();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user