Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #478 - Zeegomo:prometheus, r=pietroalbini
add metrics endpoint Fixes #477 Record metrics about jobs completed by each agent and make them available to prometheus
- Loading branch information
Showing
7 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::prelude::*; | ||
use prometheus::{IntCounterVec, __register_counter_vec}; | ||
|
||
#[derive(Clone)] | ||
pub struct Metrics { | ||
crater_completed_jobs_total: IntCounterVec, | ||
} | ||
|
||
impl Metrics { | ||
pub fn new() -> Fallible<Self> { | ||
let opts = prometheus::opts!("crater_completed_jobs_total", "total completed jobs"); | ||
let crater_completed_jobs_total = | ||
prometheus::register_int_counter_vec!(opts, &["agent", "experiment"])?; | ||
Ok(Metrics { | ||
crater_completed_jobs_total, | ||
}) | ||
} | ||
|
||
pub fn record_completed_jobs(&self, agent: &str, experiment: &str, amount: i64) { | ||
self.crater_completed_jobs_total | ||
.with_label_values(&[&agent, &experiment]) | ||
.inc_by(amount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use crate::prelude::*; | ||
use http::{Response, StatusCode}; | ||
use hyper::Body; | ||
use prometheus::{Encoder, TextEncoder}; | ||
use warp::{self, Filter, Rejection}; | ||
|
||
pub fn routes() -> impl Filter<Extract = (Response<Body>,), Error = Rejection> + Clone { | ||
warp::get2() | ||
.and(warp::path::end()) | ||
.map(|| match endpoint_metrics() { | ||
Ok(resp) => resp, | ||
Err(err) => { | ||
error!("error while processing metrics"); | ||
crate::utils::report_failure(&err); | ||
|
||
let mut resp = Response::new(format!("Error: {}\n", err).into()); | ||
*resp.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; | ||
resp | ||
} | ||
}) | ||
} | ||
|
||
fn endpoint_metrics() -> Fallible<Response<Body>> { | ||
let mut buffer = Vec::new(); | ||
let families = prometheus::gather(); | ||
TextEncoder::new().encode(&families, &mut buffer)?; | ||
Ok(Response::new(Body::from(buffer))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod agent; | ||
pub mod metrics; | ||
pub mod ui; | ||
pub mod webhooks; |