Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Monitoring status code (#194)
Browse files Browse the repository at this point in the history
* Add status code to monitoring

* Bump app version to 1.5.1
  • Loading branch information
rmeissner authored Nov 23, 2020
1 parent 61eb46a commit df738e8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "safe-client-gateway"
version = "1.5.0"
version = "1.5.1"
authors = ["jpalvarezl <[email protected]>"]
edition = "2018"

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn main() {
rocket::ignite()
.mount("/", active_routes())
.manage(reqwest::blocking::Client::new())
.attach(monitoring::request_timer::RequestTimer())
.attach(monitoring::performance::PerformanceMonitor())
.attach(CORS())
.attach(ServiceCache::fairing())
.register(error_catchers())
Expand Down
2 changes: 1 addition & 1 deletion src/monitoring/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod request_timer;
pub mod performance;
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ use chrono::Utc;
use rocket::fairing::{Fairing, Info, Kind};
use rocket::{Data, Request, Response};

pub struct RequestTimer();
pub struct PerformanceMonitor();

impl Fairing for RequestTimer {
impl Fairing for PerformanceMonitor {
fn info(&self) -> Info {
Info {
name: "RequestTimer",
name: "PerformanceMonitor",
kind: Kind::Request | Kind::Response,
}
}
Expand All @@ -16,7 +16,7 @@ impl Fairing for RequestTimer {
request.local_cache(|| Utc::now().timestamp_millis());
}

fn on_response(&self, request: &Request, _response: &mut Response) {
fn on_response(&self, request: &Request, response: &mut Response) {
let path_data = request
.route()
.map(|route| route.uri.to_string())
Expand All @@ -25,7 +25,8 @@ impl Fairing for RequestTimer {
.local_cache(|| Utc::now().timestamp_millis())
.to_owned();
let method = request.method().as_str();
let status_code = response.status().code;
let delta = Utc::now().timestamp_millis() - cached;
log::info!("MT::{}::{}::{}", method, path_data, delta)
log::info!("MT::{}::{}::{}::{}", method, path_data, delta, status_code)
}
}

0 comments on commit df738e8

Please sign in to comment.