pub struct MetricsServer { /* private fields */ }Expand description
HTTP server for exposing Prometheus metrics.
The server provides a /metrics endpoint that returns all registered metrics
in Prometheus text exposition format. The server runs asynchronously and can
be gracefully shut down.
Implementations§
Source§impl MetricsServer
impl MetricsServer
Sourcepub fn new(config: MetricsServerConfig, registry: MetricsRegistry) -> Self
pub fn new(config: MetricsServerConfig, registry: MetricsRegistry) -> Self
Creates a new metrics server with the given configuration and registry.
§Arguments
config- Server configuration (bind address and port)registry- Metrics registry to export
§Example
use elara_runtime::observability::metrics::MetricsRegistry;
use elara_runtime::observability::metrics_server::{MetricsServer, MetricsServerConfig};
let registry = MetricsRegistry::new();
let config = MetricsServerConfig::default();
let server = MetricsServer::new(config, registry);Sourcepub async fn start(&mut self) -> Result<(), MetricsServerError>
pub async fn start(&mut self) -> Result<(), MetricsServerError>
Starts the metrics server.
This method spawns the HTTP server on a background task and returns immediately.
The server will continue running until shutdown() is called or the process exits.
§Errors
Returns MetricsServerError::BindError if the server cannot bind to the
specified address/port (e.g., port already in use).
§Example
let registry = MetricsRegistry::new();
let config = MetricsServerConfig::default();
let mut server = MetricsServer::new(config, registry);
server.start().await?;Sourcepub async fn shutdown(&mut self)
pub async fn shutdown(&mut self)
Shuts down the metrics server gracefully.
This method aborts the server task and waits for it to complete.
After shutdown, the server can be restarted by calling start() again.
§Example
let mut server = MetricsServer::new(config, registry);
server.start().await?;
// ... do work ...
server.shutdown().await;Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Returns true if the server is currently running.
Sourcepub fn bind_address(&self) -> &str
pub fn bind_address(&self) -> &str
Returns the configured bind address.
Auto Trait Implementations§
impl Freeze for MetricsServer
impl !RefUnwindSafe for MetricsServer
impl Send for MetricsServer
impl Sync for MetricsServer
impl Unpin for MetricsServer
impl UnsafeUnpin for MetricsServer
impl !UnwindSafe for MetricsServer
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§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