Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Add /metrics endpoint for Prometheus (#724)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmegaJak authored Oct 6, 2023
1 parent 259c5ef commit dfa43f3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 17 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ actix-multipart = "0.6.0"
actix-cors = "0.6.4"
actix-ws = "0.2.5"
actix-files = "0.6.2"
actix-web-prom = "0.7.0"

tokio = { version = "1.29.1", features = ["sync"] }
tokio-stream = "0.1.14"
Expand All @@ -37,7 +38,7 @@ hyper-tls = "0.5.0"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_with = "3.0.0"
chrono = { version = "0.4.26", features = ["serde"]}
chrono = { version = "0.4.26", features = ["serde"] }
yaserde = "0.8.0"
yaserde_derive = "0.8.0"
xml-rs = "0.8.15"
Expand Down Expand Up @@ -72,9 +73,21 @@ log = "0.4.19"
env_logger = "0.10.0"
thiserror = "1.0.41"

sqlx = { version = "0.6.3", features = ["offline", "runtime-tokio-rustls", "postgres", "chrono", "macros", "migrate", "decimal", "json"] }
rust_decimal = { version = "1.30.0", features = ["serde-with-float", "serde-with-str"] }
redis = { version = "0.23.0", features = ["tokio-comp", "ahash", "r2d2"]}
sqlx = { version = "0.6.3", features = [
"offline",
"runtime-tokio-rustls",
"postgres",
"chrono",
"macros",
"migrate",
"decimal",
"json",
] }
rust_decimal = { version = "1.30.0", features = [
"serde-with-float",
"serde-with-str",
] }
redis = { version = "0.23.0", features = ["tokio-comp", "ahash", "r2d2"] }
deadpool-redis = "0.12.0"
clickhouse = { version = "0.11.2", features = ["uuid", "time"] }
uuid = { version = "1.2.2", features = ["v4", "fast-rng", "serde"] }
Expand Down
7 changes: 7 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use actix_web::{App, HttpServer};
use actix_web_prom::PrometheusMetricsBuilder;
use env_logger::Env;
use labrinth::database::redis::RedisPool;
use labrinth::file_hosting::S3Host;
Expand Down Expand Up @@ -88,6 +89,11 @@ async fn main() -> std::io::Result<()> {

let store = MemoryStore::new();

let prometheus = PrometheusMetricsBuilder::new("labrinth")
.endpoint("/metrics")
.build()
.expect("Failed to create prometheus metrics middleware");

info!("Starting Actix HTTP server!");

let labrinth_config = labrinth::app_setup(
Expand All @@ -101,6 +107,7 @@ async fn main() -> std::io::Result<()> {
// Init App
HttpServer::new(move || {
App::new()
.wrap(prometheus.clone())
.wrap(actix_web::middleware::Compress::default())
.wrap(
RateLimiter::new(MemoryStoreActor::from(store.clone()).start())
Expand Down

0 comments on commit dfa43f3

Please sign in to comment.