pub struct Metrics { /* private fields */ }Expand description
Prometheus metrics handle for the control plane.
Wraps a PrometheusHandle and the process start time used to
compute lightshuttle_uptime_seconds at scrape time.
§Lifecycle
Call Metrics::install once per process to register the global
Prometheus recorder. Pass the resulting value (wrapped in an
std::sync::Arc) to crate::ControlState::with_metrics so
GET /metrics can render a live snapshot.
For tests and embedders that do not need metrics, build with
Metrics::for_test, which does not touch the global recorder.
§Tracked metrics
| Metric name | Kind | Description |
|---|---|---|
lightshuttle_restart_total | counter | Accepted restart requests |
lightshuttle_lifecycle_event_duration_seconds | histogram | Seconds from start to healthy |
lightshuttle_resources | gauge (per status label) | Managed resource count |
lightshuttle_uptime_seconds | gauge | Process uptime |
Implementations§
Source§impl Metrics
impl Metrics
Sourcepub fn install() -> Self
pub fn install() -> Self
Install the global Prometheus recorder and describe every metric. Call exactly once per process, before any metric is recorded.
§Panics
Panics if a global recorder is already installed.
Sourcepub fn for_test() -> Self
pub fn for_test() -> Self
Build a non-installing handle for tests.
The metrics! macros always target the globally installed
recorder, which this constructor never sets. The returned handle
therefore renders an empty snapshot regardless of any metric
recorded elsewhere. Use Self::install plus
super::ControlState::with_metrics to serve live metrics.
Sourcepub fn render(&self, status_counts: &[(&str, u64)]) -> String
pub fn render(&self, status_counts: &[(&str, u64)]) -> String
Render the current metrics snapshot in Prometheus text format.
Before serialising, this method refreshes the two scrape-time gauges:
lightshuttle_resources{status="<s>"}for each(status, count)pair instatus_counts.lightshuttle_uptime_secondsderived from the process start time.
The returned string is suitable for serving directly as the body of
GET /metrics with content type text/plain; version=0.0.4.
Auto Trait Implementations§
impl Freeze for Metrics
impl RefUnwindSafe for Metrics
impl Send for Metrics
impl Sync for Metrics
impl Unpin for Metrics
impl UnsafeUnpin for Metrics
impl UnwindSafe for Metrics
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request