pub struct KeyStats {
pub env_var: String,
pub total_requests: u64,
pub successes: u64,
pub failures: u64,
pub rate_limits: u64,
pub total_latency_ms: u64,
pub total_input_tokens: u64,
pub total_output_tokens: u64,
pub active_requests: u64,
pub last_rate_limit_at: u64,
pub last_success_at: u64,
}Expand description
Per-key performance statistics.
Fields§
§env_var: StringWhich env var this key came from.
total_requests: u64Total requests made with this key.
successes: u64Total successful requests.
failures: u64Total failed requests (non-429).
rate_limits: u64Total 429 (rate-limit) responses.
total_latency_ms: u64Cumulative latency in ms (for computing average).
total_input_tokens: u64Total input tokens processed.
total_output_tokens: u64Total output tokens produced.
active_requests: u64Currently in-flight requests (not serialized).
last_rate_limit_at: u64Unix timestamp of last rate-limit (0 = never).
last_success_at: u64Unix timestamp of last successful request.
Implementations§
Source§impl KeyStats
impl KeyStats
Sourcepub fn avg_latency_ms(&self) -> f64
pub fn avg_latency_ms(&self) -> f64
Average latency in ms. Returns 0 if no requests completed.
Sourcepub fn success_rate(&self) -> f64
pub fn success_rate(&self) -> f64
Success rate (0.0 to 1.0). Returns 0.5 prior if no data.
Sourcepub fn is_rate_limited(&self) -> bool
pub fn is_rate_limited(&self) -> bool
Whether this key is in cooldown from a recent rate-limit.
Sourcepub fn estimated_cost(&self, input_per_mtok: f64, output_per_mtok: f64) -> f64
pub fn estimated_cost(&self, input_per_mtok: f64, output_per_mtok: f64) -> f64
Estimated cost in USD based on token counts and per-million-token rates.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for KeyStats
impl<'de> Deserialize<'de> for KeyStats
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for KeyStats
impl RefUnwindSafe for KeyStats
impl Send for KeyStats
impl Sync for KeyStats
impl Unpin for KeyStats
impl UnsafeUnpin for KeyStats
impl UnwindSafe for KeyStats
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
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>
Converts
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>
Converts
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