[−][src]Struct rocket_prometheus::PrometheusMetrics
Fairing and Handler implementing request instrumentation.
By default this tracks two metrics:
rocket_http_requests_total
(labels: endpoint, method, status): the total number of HTTP requests handled by Rocket.rocket_http_requests_duration_seconds
(labels: endpoint, method, status): the request duration for all HTTP requests handled by Rocket.
The 'rocket' prefix of these metrics can be changed by setting the
ROCKET_PROMETHEUS_NAMESPACE
environment variable.
Usage
Simply attach and mount a PrometheusMetrics
instance to your Rocket
app as for a normal fairing / handler:
use rocket_prometheus::PrometheusMetrics; let prometheus = PrometheusMetrics::new(); rocket::ignite() .attach(prometheus.clone()) .mount("/metrics", prometheus) .launch();
Metrics will then be available on the "/metrics" endpoint:
$ curl localhost:8000/metrics
# HELP rocket_http_requests_duration_seconds HTTP request duration in seconds for all requests
# TYPE rocket_http_requests_duration_seconds histogram
rocket_http_requests_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="0.005"} 2
rocket_http_requests_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="0.01"} 2
rocket_http_requests_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="0.025"} 2
rocket_http_requests_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="0.05"} 2
rocket_http_requests_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="0.1"} 2
rocket_http_requests_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="0.25"} 2
rocket_http_requests_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="0.5"} 2
rocket_http_requests_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="1"} 2
rocket_http_requests_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="2.5"} 2
rocket_http_requests_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="5"} 2
rocket_http_requests_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="10"} 2
rocket_http_requests_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="+Inf"} 2
rocket_http_requests_duration_seconds_sum{endpoint="/metrics",method="GET",status="200"} 0.0011045669999999999
rocket_http_requests_duration_seconds_count{endpoint="/metrics",method="GET",status="200"} 2
# HELP rocket_http_requests_total Total number of HTTP requests
# TYPE rocket_http_requests_total counter
rocket_http_requests_total{endpoint="/metrics",method="GET",status="200"} 2
Implementations
impl PrometheusMetrics
[src]
pub fn registry(&self) -> &Registry
[src]
Get the registry used by this fairing.
You can use this to register further metrics, causing them to be exposed along with the default metrics on the PrometheusMetrics handler.
use once_cell::sync::Lazy; use prometheus::{opts, IntCounter}; use rocket_prometheus::PrometheusMetrics; static MY_COUNTER: Lazy<IntCounter> = Lazy::new(|| { IntCounter::new("my_counter", "A counter I use a lot") .expect("Could not create counter") }); let prometheus = PrometheusMetrics::new(); prometheus.registry().register(Box::new(MY_COUNTER.clone()));
impl PrometheusMetrics
[src]
pub fn new() -> Self
[src]
Create a new PrometheusMetrics
.
pub fn with_registry(registry: Registry) -> Self
[src]
Create a new PrometheusMetrics
with a custom Registry
.
Trait Implementations
impl Clone for PrometheusMetrics
[src]
fn clone(&self) -> PrometheusMetrics
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Default for PrometheusMetrics
[src]
impl Fairing for PrometheusMetrics
[src]
fn info(&self) -> Info
[src]
fn on_request(&self, request: &mut Request, _: &Data)
[src]
fn on_response(&self, request: &Request, response: &mut Response)
[src]
fn on_attach(&self, rocket: Rocket) -> Result<Rocket, Rocket>
[src]
fn on_launch(&self, rocket: &Rocket)
[src]
impl Handler for PrometheusMetrics
[src]
impl Into<Vec<Route>> for PrometheusMetrics
[src]
Auto Trait Implementations
impl !RefUnwindSafe for PrometheusMetrics
impl Send for PrometheusMetrics
impl Sync for PrometheusMetrics
impl Unpin for PrometheusMetrics
impl !UnwindSafe for PrometheusMetrics
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T, I> AsResult<T, I> for T where
I: Input,
I: Input,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Cloneable for T where
T: Handler + Clone,
[src]
T: Handler + Clone,
fn clone_handler(&self) -> Box<dyn Handler + 'static>
[src]
impl<T> From<T> for T
[src]
impl<F> Handler for F where
F: 'static + Clone + Send + Sync + for<'r> Fn(&'r Request, Data) -> Outcome<Response<'r>, Status, Data>,
[src]
F: 'static + Clone + Send + Sync + for<'r> Fn(&'r Request, Data) -> Outcome<Response<'r>, Status, Data>,
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoCollection<T> for T
fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
A: Array<Item = T>,
fn mapped<U, F, A>(self, f: F) -> SmallVec<A> where
A: Array<Item = U>,
F: FnMut(T) -> U,
A: Array<Item = U>,
F: FnMut(T) -> U,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Typeable for T where
T: Any,
T: Any,