pub struct HostStats {
pub total_requests: u64,
pub successful_requests: u64,
pub rate_limited: u64,
pub server_errors: u64,
pub client_errors: u64,
pub last_success: Option<Instant>,
pub last_rate_limit: Option<Instant>,
pub request_times: Vec<Duration>,
pub status_codes: HashMap<u16, u64>,
pub cache_hits: u64,
pub cache_misses: u64,
}Expand description
Record and report statistics for a crate::ratelimit::Host
Fields§
§total_requests: u64Total number of requests made to this host
successful_requests: u64Number of successful requests (2xx status)
rate_limited: u64Number of requests that received rate limit responses (429)
server_errors: u64Number of server error responses (5xx)
client_errors: u64Number of client error responses (4xx, excluding 429)
last_success: Option<Instant>Timestamp of the last successful request
last_rate_limit: Option<Instant>Timestamp of the last rate limit response
request_times: Vec<Duration>Request times for median calculation
status_codes: HashMap<u16, u64>Status code counts
cache_hits: u64Number of cache hits
cache_misses: u64Number of cache misses
Implementations§
Source§impl HostStats
impl HostStats
Sourcepub fn record_response(&mut self, status_code: u16, request_time: Duration)
pub fn record_response(&mut self, status_code: u16, request_time: Duration)
Record a response with status code and request duration
Sourcepub fn median_request_time(&self) -> Option<Duration>
pub fn median_request_time(&self) -> Option<Duration>
Get median request time
Sourcepub fn error_rate(&self) -> f64
pub fn error_rate(&self) -> f64
Get error rate (percentage)
Sourcepub fn success_rate(&self) -> f64
pub fn success_rate(&self) -> f64
Get the current success rate (0.0 to 1.0)
Sourcepub fn average_request_time(&self) -> Option<Duration>
pub fn average_request_time(&self) -> Option<Duration>
Get average request time
Sourcepub fn latest_request_time(&self) -> Option<Duration>
pub fn latest_request_time(&self) -> Option<Duration>
Get the most recent request time
Sourcepub fn is_currently_rate_limited(&self) -> bool
pub fn is_currently_rate_limited(&self) -> bool
Check if this host has been experiencing rate limiting recently
Sourcepub const fn record_cache_hit(&mut self)
pub const fn record_cache_hit(&mut self)
Record a cache hit
Sourcepub const fn record_cache_miss(&mut self)
pub const fn record_cache_miss(&mut self)
Record a cache miss
Sourcepub fn cache_hit_rate(&self) -> f64
pub fn cache_hit_rate(&self) -> f64
Get cache hit rate (0.0 to 1.0)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for HostStats
impl RefUnwindSafe for HostStats
impl Send for HostStats
impl Sync for HostStats
impl Unpin for HostStats
impl UnwindSafe for HostStats
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more