pub struct PrometheusMetrics {
pub requests_total: LabeledCounter,
pub request_duration_seconds: LabeledHistogram,
pub active_connections: Counter,
pub bytes_total: LabeledCounter,
pub errors_total: LabeledCounter,
/* private fields */
}Expand description
Prometheus-compatible metrics
Fields§
§requests_total: LabeledCounterRequest counter by method
request_duration_seconds: LabeledHistogramRequest latency histogram by method
active_connections: CounterActive connections gauge
bytes_total: LabeledCounterBytes transferred counter (by direction: “in” or “out”)
errors_total: LabeledCounterError counter by type
Implementations§
Source§impl PrometheusMetrics
impl PrometheusMetrics
Sourcepub fn new(config: MetricsConfig) -> Self
pub fn new(config: MetricsConfig) -> Self
Create new Prometheus metrics
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create with default configuration
Sourcepub fn record_request(&self, method: &str, duration: Duration)
pub fn record_request(&self, method: &str, duration: Duration)
Record a request
Sourcepub fn record_error(&self, error_type: &str)
pub fn record_error(&self, error_type: &str)
Record an error
Sourcepub fn record_bytes(&self, direction: &str, bytes: u64)
pub fn record_bytes(&self, direction: &str, bytes: u64)
Record bytes transferred
Sourcepub fn connection_opened(&self)
pub fn connection_opened(&self)
Increment active connections
Sourcepub fn connection_closed(&self)
pub fn connection_closed(&self)
Decrement active connections (using a separate counter for simplicity)
Sourcepub fn config(&self) -> &MetricsConfig
pub fn config(&self) -> &MetricsConfig
Get configuration
Sourcepub fn format_prometheus(&self) -> String
pub fn format_prometheus(&self) -> String
Format metrics in Prometheus text format
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for PrometheusMetrics
impl RefUnwindSafe for PrometheusMetrics
impl Send for PrometheusMetrics
impl Sync for PrometheusMetrics
impl Unpin for PrometheusMetrics
impl UnsafeUnpin for PrometheusMetrics
impl UnwindSafe for PrometheusMetrics
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
Mutably borrows from an owned value. Read more