All Projects → sd2k → rocket_prometheus

sd2k / rocket_prometheus

Licence: Apache-2.0, MIT licenses found Licenses found Apache-2.0 LICENSE-APACHE MIT LICENSE-MIT
Prometheus fairing and handler for Rocket

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to rocket prometheus

Starter Kit
📦 Angular 11+ starter kit for enterprise-grade projects
Stars: ✭ 1,102 (+2800%)
Mutual labels:  rocket
Rrinlog
Replacing Elasticsearch with Rust and SQLite
Stars: ✭ 129 (+239.47%)
Mutual labels:  rocket
rocket-lamb
A crate to allow running a Rocket webserver as an AWS Lambda Function with API Gateway or an Application Load Balancer
Stars: ✭ 73 (+92.11%)
Mutual labels:  rocket
Accord
Data validation library for Rust
Stars: ✭ 72 (+89.47%)
Mutual labels:  rocket
Openmotor
An open-source internal ballistics simulator for rocket motor experimenters
Stars: ✭ 107 (+181.58%)
Mutual labels:  rocket
Rocket
A web framework for Rust.
Stars: ✭ 15,760 (+41373.68%)
Mutual labels:  rocket
Giropops Monitoring
Full stack tools for monitoring containers and other stuff. ;)
Stars: ✭ 1,019 (+2581.58%)
Mutual labels:  rocket
MAPLEAF
6-DOF Rocket Flight Simulation Framework
Stars: ✭ 28 (-26.32%)
Mutual labels:  rocket
Plume
Federated blogging application, thanks to ActivityPub (now on https://git.joinplu.me/ — this is just a mirror)
Stars: ✭ 1,615 (+4150%)
Mutual labels:  rocket
rocket auth
An implementation for an authentication API for Rocket applications.
Stars: ✭ 65 (+71.05%)
Mutual labels:  rocket
Rocket cors
Cross-origin resource sharing (CORS) for Rocket.rs applications
Stars: ✭ 73 (+92.11%)
Mutual labels:  rocket
Generator Ngx Rocket
🚀 Extensible Angular 11+ enterprise-grade project generator
Stars: ✭ 1,329 (+3397.37%)
Mutual labels:  rocket
Rust Web Boilerplate
Rust web template for modern web backend applications
Stars: ✭ 211 (+455.26%)
Mutual labels:  rocket
Spacex Api
🚀 Open Source REST API for SpaceX launch, rocket, core, capsule, starlink, launchpad, and landing pad data.
Stars: ✭ 8,973 (+23513.16%)
Mutual labels:  rocket
Unreal-Binary-Builder
An application designed to create installed Unreal Engine builds (aka Rocket builds) from Unreal Engine GitHub source.
Stars: ✭ 554 (+1357.89%)
Mutual labels:  rocket
Rocket.chat.ios
Legacy mobile Rocket.Chat client in Swift for iOS
Stars: ✭ 1,028 (+2605.26%)
Mutual labels:  rocket
Ciapre Xcode Theme
An easy on the eyes Xcode color scheme, ported from Ciapre Sublime Text.
Stars: ✭ 130 (+242.11%)
Mutual labels:  rocket
bin
highly opinionated, minimal pastebin
Stars: ✭ 97 (+155.26%)
Mutual labels:  rocket
Rocket
Define your release steps 🚀
Stars: ✭ 99 (+160.53%)
Mutual labels:  rocket
rust-for-backend-development
SWITCH TO RUST AND STOP WASTING YOUR TIME WITH JAVASCRIPT RUNTIME EXCEPTIONS
Stars: ✭ 30 (-21.05%)
Mutual labels:  rocket

Rocket Prometheus

Build Status docs.rs crates.io

Prometheus instrumentation for Rocket applications.

Usage

Add this crate to your Cargo.toml alongside Rocket 0.5.0-rc.2:

[dependencies]
rocket = "0.5.0-rc.2"
rocket_prometheus = "0.10.0-rc.3"

Then attach and mount a PrometheusMetrics instance to your Rocket app:

use rocket_prometheus::PrometheusMetrics;

#[rocket::launch]
fn launch() -> _ {
    let prometheus = PrometheusMetrics::new();
    rocket::build()
        .attach(prometheus.clone())
        .mount("/metrics", prometheus)

This will expose metrics like this at the /metrics endpoint of your application:

$ 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

Metrics

By default this crate 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.

Custom Metrics

Further metrics can be tracked by registering them with the registry of the PrometheusMetrics instance:

#[macro_use]
use once_cell::sync::Lazy;
use rocket::{get, launch, routes};
use rocket_prometheus::{
    prometheus::{opts, IntCounterVec},
    PrometheusMetrics,
};

static NAME_COUNTER: Lazy<IntCounterVec> = Lazy::new(|| {
    IntCounterVec::new(opts!("name_counter", "Count of names"), &["name"])
        .expect("Could not create NAME_COUNTER")
});

#[get("/hello/<name>")]
pub fn hello(name: &str) -> String {
    NAME_COUNTER.with_label_values(&[name]).inc();
    format!("Hello, {}!", name)
}

#[launch]
fn launch() -> _ {
    let prometheus = PrometheusMetrics::new();
    prometheus
        .registry()
        .register(Box::new(NAME_COUNTER.clone()))
        .unwrap();
    rocket::build()
        .attach(prometheus.clone())
        .mount("/", routes![hello])
        .mount("/metrics", prometheus)
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].