ServerMetrics

Struct ServerMetrics 

Source
pub struct ServerMetrics {
Show 23 fields pub requests_total: AtomicU64, pub requests_successful: AtomicU64, pub requests_failed: AtomicU64, pub requests_in_flight: AtomicU64, pub errors_total: AtomicU64, pub errors_validation: AtomicU64, pub errors_auth: AtomicU64, pub errors_network: AtomicU64, pub errors_timeout: AtomicU64, pub total_response_time_us: AtomicU64, pub min_response_time_us: AtomicU64, pub max_response_time_us: AtomicU64, pub tool_calls_total: AtomicU64, pub tool_calls_successful: AtomicU64, pub tool_calls_failed: AtomicU64, pub connections_active: AtomicU64, pub connections_total: AtomicU64, pub connections_rejected: AtomicU64, pub memory_usage_bytes: AtomicU64, pub cpu_usage_percent_x100: AtomicU64, pub custom: RwLock<HashMap<String, f64>>, pub response_time_buckets: ResponseTimeHistogram, pub start_time: Instant,
}
Expand description

Production-grade server metrics collector with lock-free atomic operations

Fields§

§requests_total: AtomicU64

Total number of requests received since server start

§requests_successful: AtomicU64

Number of requests that completed successfully

§requests_failed: AtomicU64

Number of requests that failed with errors

§requests_in_flight: AtomicU64

Number of requests currently being processed

§errors_total: AtomicU64

Total number of errors across all categories

§errors_validation: AtomicU64

Number of validation/schema errors

§errors_auth: AtomicU64

Number of authentication/authorization errors

§errors_network: AtomicU64

Number of network-related errors

§errors_timeout: AtomicU64

Number of timeout errors

§total_response_time_us: AtomicU64

Sum of all response times in microseconds

§min_response_time_us: AtomicU64

Minimum response time observed (microseconds)

§max_response_time_us: AtomicU64

Maximum response time observed (microseconds)

§tool_calls_total: AtomicU64

Total number of tool calls initiated

§tool_calls_successful: AtomicU64

Number of tool calls that completed successfully

§tool_calls_failed: AtomicU64

Number of tool calls that failed

§connections_active: AtomicU64

Number of currently active connections

§connections_total: AtomicU64

Total connections accepted since server start

§connections_rejected: AtomicU64

Number of connections rejected (rate limiting, etc.)

§memory_usage_bytes: AtomicU64

Current memory usage in bytes

§cpu_usage_percent_x100: AtomicU64

Current CPU usage as percentage × 100 (due to no AtomicF64)

§custom: RwLock<HashMap<String, f64>>

Custom application-specific metrics (rare updates, RwLock acceptable)

§response_time_buckets: ResponseTimeHistogram

Response time histogram for latency distribution analysis

§start_time: Instant

Server start time for uptime calculation

Implementations§

Source§

impl ServerMetrics

Source

pub fn new() -> Self

Create production-grade metrics collector with comprehensive initialization

Source

pub fn record_request_start(&self)

Record request start with zero-allocation tracking

Source

pub fn record_request_success(&self, duration: Duration)

Record successful request completion with timing

Source

pub fn record_request_failure(&self, error_type: &str, duration: Duration)

Record failed request with error categorization

Source

pub fn record_tool_call(&self, success: bool)

Record tool call metrics with comprehensive tracking

Source

pub fn record_connection_established(&self)

Update connection metrics with proper lifecycle tracking

Source

pub fn record_connection_closed(&self)

Record when a connection is closed/terminated

Source

pub fn record_connection_rejected(&self)

Record when a connection is rejected due to rate limiting or other policies

Source

pub fn update_resource_metrics(&self, memory_bytes: u64, cpu_percent: f64)

Update resource metrics (called periodically by monitoring task)

Source

pub fn record_custom(&self, name: &str, value: f64)

Record custom metric (infrequent operation, lock acceptable)

Source

pub fn uptime_seconds(&self) -> u64

Calculate uptime in seconds

Source

pub fn avg_response_time_us(&self) -> f64

Calculate average response time in microseconds

Source

pub fn request_rate(&self) -> f64

Calculate request rate (requests per second)

Source

pub fn error_rate_percent(&self) -> f64

Calculate error rate as percentage

Trait Implementations§

Source§

impl Debug for ServerMetrics

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ServerMetrics

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,