Skip to content

Commit ccf587b

Browse files
committed
rocket: Add in an internal metrics reporting url for prometheus
1 parent 65edd3e commit ccf587b

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ authors = ["Alexander von Gluck IV <[email protected]>"]
66
[dependencies]
77
natord = "1.0.9"
88
rocket = "0.4"
9+
rocket_prometheus = "0.9.0"
910
regex = "*"
1011
rust-s3 = { version = "0.29", features = ["default", "blocking"] }
1112
serde = "*"

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extern crate regex;
1515

1616
#[macro_use]
1717
extern crate rocket;
18+
extern crate rocket_prometheus;
1819

1920
extern crate toml;
2021
extern crate s3;
@@ -32,6 +33,7 @@ use rocket::State;
3233
use rocket::http::Status;
3334
use rocket::response::{Response, Redirect};
3435
use rocket::request::Request;
36+
use rocket_prometheus::PrometheusMetrics;
3537

3638
mod routecache;
3739

@@ -152,6 +154,7 @@ fn main() {
152154
Err(e) => println!("Cache Sync Error: {}", e),
153155
};
154156

157+
let prometheus = PrometheusMetrics::new();
155158

156159
// This mutex gets consumed by multiple threads (the cache rebuilder, and every route.
157160
let cache_state = Arc::new(Mutex::new(cache));
@@ -172,7 +175,9 @@ fn main() {
172175
// Launch our web server, begin serving requests
173176
rocket::ignite()
174177
.manage(cache_state.clone())
178+
.attach(prometheus.clone())
175179
.mount("/", routes![sys_health, index, index_branch, index_arch, index_repo, access_repo])
180+
.mount("/metrics", prometheus)
176181
.register(catchers![sys_not_found])
177182
.launch();
178183
}

0 commit comments

Comments
 (0)