@@ -21,6 +21,7 @@ use actix_web::dev::ServiceRequest;
2121use actix_web:: { middleware, web, App , HttpServer } ;
2222use actix_web_httpauth:: extractors:: basic:: BasicAuth ;
2323use actix_web_httpauth:: middleware:: HttpAuthentication ;
24+ use actix_web_prometheus:: { PrometheusMetrics , PrometheusMetricsBuilder } ;
2425use actix_web_static_files:: ResourceFiles ;
2526use clokwerk:: { AsyncScheduler , Scheduler , TimeUnits } ;
2627use log:: warn;
@@ -68,6 +69,11 @@ async fn main() -> anyhow::Result<()> {
6869 CONFIG . validate_storage ( & * storage) . await ;
6970 let metadata = storage:: resolve_parseable_metadata ( ) . await ?;
7071 banner:: print ( & CONFIG , metadata) ;
72+ let prometheus = PrometheusMetricsBuilder :: new ( env ! ( "CARGO_PKG_NAME" ) )
73+ . registry ( prometheus:: default_registry ( ) . clone ( ) )
74+ . endpoint ( "/metrics" )
75+ . build ( )
76+ . unwrap ( ) ;
7177
7278 migration:: run_migration ( & CONFIG ) . await ?;
7379
@@ -82,7 +88,7 @@ async fn main() -> anyhow::Result<()> {
8288 let ( mut remote_sync_handler, mut remote_sync_outbox, mut remote_sync_inbox) =
8389 object_store_sync ( ) ;
8490
85- let app = run_http ( ) ;
91+ let app = run_http ( prometheus ) ;
8692 tokio:: pin!( app) ;
8793 loop {
8894 tokio:: select! {
@@ -206,7 +212,7 @@ async fn validator(
206212 Err ( ( actix_web:: error:: ErrorUnauthorized ( "Unauthorized" ) , req) )
207213}
208214
209- async fn run_http ( ) -> anyhow:: Result < ( ) > {
215+ async fn run_http ( prometheus : PrometheusMetrics ) -> anyhow:: Result < ( ) > {
210216 let ssl_acceptor = match (
211217 & CONFIG . parseable . tls_cert_path ,
212218 & CONFIG . parseable . tls_key_path ,
@@ -242,7 +248,7 @@ async fn run_http() -> anyhow::Result<()> {
242248 } ;
243249
244250 // concurrent workers equal to number of cores on the cpu
245- let http_server = HttpServer :: new ( move || create_app ! ( ) ) . workers ( num_cpus:: get ( ) ) ;
251+ let http_server = HttpServer :: new ( move || create_app ! ( prometheus ) ) . workers ( num_cpus:: get ( ) ) ;
246252 if let Some ( config) = ssl_acceptor {
247253 http_server
248254 . bind_rustls ( & CONFIG . parseable . address , config) ?
@@ -313,8 +319,9 @@ pub fn configure_routes(cfg: &mut web::ServiceConfig) {
313319
314320#[ macro_export]
315321macro_rules! create_app {
316- ( ) => {
322+ ( $prometheus : expr ) => {
317323 App :: new( )
324+ . wrap( $prometheus. clone( ) )
318325 . configure( |cfg| configure_routes( cfg) )
319326 . wrap( middleware:: Logger :: default ( ) )
320327 . wrap( middleware:: Compress :: default ( ) )
0 commit comments