Skip to content

Commit 9e5fe75

Browse files
Prometheus metrics endpoint
This starts tracking the queue length over time, so we can get some sense of when the perf server begins to approach capacity. More detailed metrics to be added later.
1 parent 6e54a65 commit 9e5fe75

File tree

3 files changed

+67
-14
lines changed

3 files changed

+67
-14
lines changed

Cargo.lock

Lines changed: 44 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ analyzeme = { git = "https://github.com/rust-lang/measureme" }
4444
tar = "0.4"
4545
inferno = { version="0.10", default-features = false }
4646
mime = "0.3"
47+
prometheus = "0.11"
4748

4849
[dependencies.collector]
4950
path = "../collector"

site/src/server.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,25 @@ impl Server {
14591459
false
14601460
}
14611461

1462+
async fn handle_metrics(&self, _req: Request) -> Response {
1463+
use prometheus::Encoder;
1464+
let data: Arc<InputData> = self.data.read().as_ref().unwrap().clone();
1465+
1466+
let mut buffer = Vec::new();
1467+
let r = prometheus::Registry::new();
1468+
1469+
let queue_length = prometheus::IntGauge::new("queue_length", "queue length").unwrap();
1470+
queue_length.set(data.missing_commits().await.len() as i64);
1471+
1472+
r.register(Box::new(queue_length)).unwrap();
1473+
1474+
let encoder = prometheus::TextEncoder::new();
1475+
let metric_families = r.gather();
1476+
encoder.encode(&metric_families, &mut buffer).unwrap();
1477+
1478+
Response::new(buffer.into())
1479+
}
1480+
14621481
async fn handle_push(&self, _req: Request) -> Response {
14631482
lazy_static::lazy_static! {
14641483
static ref LAST_UPDATE: Mutex<Option<Instant>> = Mutex::new(None);
@@ -1590,6 +1609,9 @@ async fn serve_req(ctx: Arc<Server>, req: Request) -> Result<Response, ServerErr
15901609
_ => {}
15911610
}
15921611

1612+
if req.uri().path() == "/perf/metrics" {
1613+
return Ok(ctx.handle_metrics(req).await);
1614+
}
15931615
if req.uri().path() == "/perf/onpush" {
15941616
return Ok(ctx.handle_push(req).await);
15951617
}

0 commit comments

Comments
 (0)