nlopes / actix-web-prom

Actix-web middleware to expose Prometheus metrics
MIT License
93 stars 56 forks source link

Add custom registry support and None endpoint #2

Closed nWacky closed 5 years ago

nWacky commented 5 years ago

Some projects have more than one actix_web Server (for example, to separate public and private APIs). In this case user might not want to expose metrics endpoint on public server and would like to have one only on private server. I suggest making endpoint optional:

 let public_metrics = PrometheusMetrics::new("public", None);
 let private_metrics = PrometheusMetrics::new("private", Some("/metrics"));

Also for projects with multiple actix_web servers it might be useful to have one metrics endpoint for the whole project => it might be useful to share one Registry instance among multiple middlewares:

let r = Registry::new();
let public_metrics =
        PrometheusMetrics::new_with_registry(r.clone(), "public", None).unwrap();
let private_metrics =
        PrometheusMetrics::new_with_registry(r.clone(), "private", Some("/metrics")).unwrap();

This way middleware can be used in projects with one or more actix_web Servers out of the box