diff --git a/Cargo.lock b/Cargo.lock index 9743148c0..2071c3867 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -256,6 +256,21 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "actix-web-prometheus" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad5228fd1a6b5d0f60d636776c2a70acc9fc667034bb4ac02ec4259f0eeeab6c" +dependencies = [ + "actix-service", + "actix-web", + "futures-lite", + "pin-project", + "prometheus", + "quanta", + "thiserror", +] + [[package]] name = "actix-web-static-files" version = "4.0.0" @@ -1118,7 +1133,7 @@ dependencies = [ "num-integer", "num-traits", "serde", - "time 0.1.45", + "time 0.1.43", "wasm-bindgen", "winapi", ] @@ -1797,6 +1812,21 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" +[[package]] +name = "futures-lite" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + [[package]] name = "futures-macro" version = "0.3.26" @@ -2409,6 +2439,15 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + [[package]] name = "maplit" version = "1.0.2" @@ -2667,6 +2706,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f222829ae9293e33a9f5e9f440c6760a3d450a64affe1846486b140db81c1f4" +[[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + [[package]] name = "parking_lot" version = "0.12.1" @@ -2731,6 +2776,7 @@ dependencies = [ "actix-files", "actix-web", "actix-web-httpauth", + "actix-web-prometheus", "actix-web-static-files", "anyhow", "arrow-schema", @@ -2762,6 +2808,7 @@ dependencies = [ "num_cpus", "object_store", "os_info", + "prometheus", "rand", "relative-path", "rstest", @@ -2906,6 +2953,58 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "procfs" +version = "0.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1de8dacb0873f77e6aefc6d71e044761fcc68060290f5b1089fcdf84626bb69" +dependencies = [ + "bitflags", + "byteorder", + "hex", + "lazy_static", + "rustix", +] + +[[package]] +name = "prometheus" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "449811d15fbdf5ceb5c1144416066429cf82316e2ec8ce0c1f6f8a02e7bbcf8c" +dependencies = [ + "cfg-if", + "fnv", + "lazy_static", + "libc", + "memchr", + "parking_lot", + "procfs", + "protobuf", + "thiserror", +] + +[[package]] +name = "protobuf" +version = "2.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" + +[[package]] +name = "quanta" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e31331286705f455e56cca62e0e717158474ff02b7936c1fa596d983f4ae27" +dependencies = [ + "crossbeam-utils", + "libc", + "mach", + "once_cell", + "raw-cpuid", + "wasi 0.10.2+wasi-snapshot-preview1", + "web-sys", + "winapi", +] + [[package]] name = "quick-xml" version = "0.27.1" @@ -2955,6 +3054,15 @@ dependencies = [ "getrandom", ] +[[package]] +name = "raw-cpuid" +version = "10.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c307f7aacdbab3f0adee67d52739a1d71112cc068d6fab169ddeb18e48877fad" +dependencies = [ + "bitflags", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -3590,12 +3698,11 @@ dependencies = [ [[package]] name = "time" -version = "0.1.45" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "wasi 0.10.0+wasi-snapshot-preview1", "winapi", ] @@ -3705,9 +3812,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.5" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e267c18a719545b481171952a79f8c25c80361463ba44bc7fa9eba7c742ef4f" +checksum = "bc6a3b08b64e6dfad376fa2432c7b1f01522e37a623c3050bc95db2d3ff21583" dependencies = [ "bytes", "futures-core", @@ -3960,6 +4067,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + [[package]] name = "walkdir" version = "2.3.2" @@ -3983,9 +4096,9 @@ dependencies = [ [[package]] name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" +version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasi" @@ -4278,9 +4391,9 @@ dependencies = [ [[package]] name = "zstd-safe" -version = "6.0.3+zstd.1.5.2" +version = "6.0.4+zstd.1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68e4a3f57d13d0ab7e478665c60f35e2a613dcd527851c2c7287ce5c787e134a" +checksum = "7afb4b54b8910cf5447638cb54bf4e8a65cbedd783af98b98c62ffe91f185543" dependencies = [ "libc", "zstd-sys", @@ -4288,9 +4401,9 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.6+zstd.1.5.2" +version = "2.0.7+zstd.1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a3f9792c0c3dc6c165840a75f47ae1f4da402c2d006881129579f6597e801b" +checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5" dependencies = [ "cc", "libc", diff --git a/server/Cargo.toml b/server/Cargo.toml index 7a8d243de..74d3a3adb 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -11,6 +11,8 @@ actix-web-httpauth = "0.8" actix-web = { version = "4.3", features = ["rustls"] } actix-cors = "0.6" actix-files = "0.6" +actix-web-prometheus = { version = "0.1", features = ["process"] } +prometheus = { version = "0.13", features = ["process"] } anyhow = { version = "1.0", features = ["backtrace"] } arrow-schema = { version = "31.0", features = ["serde"] } async-trait = "0.1" diff --git a/server/src/main.rs b/server/src/main.rs index e59291331..d83a5480a 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -21,6 +21,7 @@ use actix_web::dev::ServiceRequest; use actix_web::{middleware, web, App, HttpServer}; use actix_web_httpauth::extractors::basic::BasicAuth; use actix_web_httpauth::middleware::HttpAuthentication; +use actix_web_prometheus::{PrometheusMetrics, PrometheusMetricsBuilder}; use actix_web_static_files::ResourceFiles; use clokwerk::{AsyncScheduler, Scheduler, TimeUnits}; use log::warn; @@ -68,6 +69,11 @@ async fn main() -> anyhow::Result<()> { CONFIG.validate_storage(&*storage).await; let metadata = storage::resolve_parseable_metadata().await?; banner::print(&CONFIG, metadata); + let prometheus = PrometheusMetricsBuilder::new(env!("CARGO_PKG_NAME")) + .registry(prometheus::default_registry().clone()) + .endpoint("/metrics") + .build() + .unwrap(); migration::run_migration(&CONFIG).await?; @@ -82,7 +88,7 @@ async fn main() -> anyhow::Result<()> { let (mut remote_sync_handler, mut remote_sync_outbox, mut remote_sync_inbox) = object_store_sync(); - let app = run_http(); + let app = run_http(prometheus); tokio::pin!(app); loop { tokio::select! { @@ -206,7 +212,7 @@ async fn validator( Err((actix_web::error::ErrorUnauthorized("Unauthorized"), req)) } -async fn run_http() -> anyhow::Result<()> { +async fn run_http(prometheus: PrometheusMetrics) -> anyhow::Result<()> { let ssl_acceptor = match ( &CONFIG.parseable.tls_cert_path, &CONFIG.parseable.tls_key_path, @@ -242,7 +248,7 @@ async fn run_http() -> anyhow::Result<()> { }; // concurrent workers equal to number of cores on the cpu - let http_server = HttpServer::new(move || create_app!()).workers(num_cpus::get()); + let http_server = HttpServer::new(move || create_app!(prometheus)).workers(num_cpus::get()); if let Some(config) = ssl_acceptor { http_server .bind_rustls(&CONFIG.parseable.address, config)? @@ -313,8 +319,9 @@ pub fn configure_routes(cfg: &mut web::ServiceConfig) { #[macro_export] macro_rules! create_app { - () => { + ($prometheus: expr) => { App::new() + .wrap($prometheus.clone()) .configure(|cfg| configure_routes(cfg)) .wrap(middleware::Logger::default()) .wrap(middleware::Compress::default())