2 unstable releases
Uses new Rust 2024
| 0.2.0 | Sep 14, 2025 |
|---|---|
| 0.1.0 | Jul 12, 2025 |
#1138 in HTTP server
170 downloads per month
17KB
125 lines
rocket_health
๐ง Drop-in
/healthroute for Rocket APIs with uptime and rolling average latency metrics.
โจ Features
- ๐ Easy integration into any Rocket API
- ๐ Tracks server uptime
- โก Measures average response latency (rolling window)
- ๐ค Exposes
/healthroute returning structured JSON
Example response:
{
"status": "ok",
"uptime_seconds": 432.123,
"mean_latency_seconds": 0.0054
}
๐ฆ Installation
Add to your Cargo.toml:
[dependencies]
rocket_health = "0.1"
rocket = { version = "0.5", features = ["json"] }
๐ Usage
Step 1: Mount health route and fairing
#[macro_use] extern crate rocket;
use rocket_health::mount_health_route;
#[launch]
fn rocket() -> _ {
let rocket = rocket::build();
mount_health_route(rocket)
}
Step 2: Start your Rocket app
The /health route is now available:
GET /health
Returns uptime and latency in seconds (float). Latency is computed using a sliding window of the last 100 requests.
๐งช Testing
You can unit test the handler or compute test coverage using cargo-tarpaulin:
cargo install cargo-tarpaulin
cargo tarpaulin --out Html --ignore-tests --line --target-dir tarpaulin-target/ --skip-clean
Dependencies
~16โ48MB
~792K SLoC