pub struct AuthMetrics {
pub entity_id: String,
pub endpoint: String,
pub failures: u32,
pub successes: u32,
pub window_start: u64,
pub last_attempt: u64,
pub total_failures: u64,
pub total_successes: u64,
pub hourly_failures: [u32; 24],
pub current_hour_index: u8,
pub last_hour_rotation: u64,
}Expand description
Per-entity authentication metrics.
Tracks auth attempts for a single entity (IP) against auth endpoints.
Fields§
§entity_id: StringEntity identifier (IP address)
endpoint: StringEndpoint being tracked (e.g., “/api/login”)
failures: u32Failed auth attempts in current window
successes: u32Successful auth attempts in current window
window_start: u64Window start timestamp (ms since epoch)
last_attempt: u64Last attempt timestamp (ms since epoch)
total_failures: u64Total failed attempts (lifetime)
total_successes: u64Total successful attempts (lifetime)
hourly_failures: [u32; 24]Hourly failure buckets (24 hours)
current_hour_index: u8Current hour index (0-23)
last_hour_rotation: u64Last hour rotation timestamp
Implementations§
Source§impl AuthMetrics
impl AuthMetrics
Sourcepub fn new(entity_id: String, endpoint: String, now: u64) -> Self
pub fn new(entity_id: String, endpoint: String, now: u64) -> Self
Create new auth metrics for an entity/endpoint pair.
Sourcepub fn record_failure(&mut self, now: u64)
pub fn record_failure(&mut self, now: u64)
Record a failed attempt.
Sourcepub fn record_success(&mut self, now: u64)
pub fn record_success(&mut self, now: u64)
Record a successful attempt.
Sourcepub fn reset_window(&mut self, now: u64)
pub fn reset_window(&mut self, now: u64)
Reset sliding window.
Sourcepub fn detect_low_and_slow(
&self,
min_hours: usize,
min_failures_per_hour: u32,
) -> bool
pub fn detect_low_and_slow( &self, min_hours: usize, min_failures_per_hour: u32, ) -> bool
Detect low-and-slow pattern (consistent failures over hours).
Returns true if failures are spread evenly across multiple hours.
Sourcepub fn failure_rate(&self, now: u64) -> f64
pub fn failure_rate(&self, now: u64) -> f64
Get failure rate (failures per second in current window).
Trait Implementations§
Source§impl Clone for AuthMetrics
impl Clone for AuthMetrics
Source§fn clone(&self) -> AuthMetrics
fn clone(&self) -> AuthMetrics
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AuthMetrics
impl Debug for AuthMetrics
Source§impl<'de> Deserialize<'de> for AuthMetrics
impl<'de> Deserialize<'de> for AuthMetrics
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>,
Auto Trait Implementations§
impl Freeze for AuthMetrics
impl RefUnwindSafe for AuthMetrics
impl Send for AuthMetrics
impl Sync for AuthMetrics
impl Unpin for AuthMetrics
impl UnsafeUnpin for AuthMetrics
impl UnwindSafe for AuthMetrics
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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