Skip to main content

Metrics

Struct Metrics 

Source
pub struct Metrics {
    pub pages_crawled: AtomicU64,
    pub pages_failed: AtomicU64,
    pub findings_generated: AtomicU64,
    pub bytes_fetched: AtomicU64,
    pub fetch_time_us: AtomicU64,
    pub analysis_time_us: AtomicU64,
    pub storage_time_us: AtomicU64,
    pub active_connections: AtomicU64,
    pub circuit_breaker_trips: AtomicU64,
    pub resource_limit_hits: AtomicU64,
    pub pages_skipped_circuit_breaker: AtomicU64,
}
Expand description

Observability metrics for crawl operations.

Thread-safe metrics collection using atomic operations. Designed for zero-allocation in hot paths. All counters use Relaxed ordering for maximum throughput.

§Examples

use crawlkit_engine::Metrics;
use std::time::Duration;

let metrics = Metrics::new();
metrics.record_page_success(1024, 100, 50, 10, 3);
assert_eq!(metrics.pages_crawled.load(std::sync::atomic::Ordering::Relaxed), 1);

Fields§

§pages_crawled: AtomicU64

Total pages crawled.

§pages_failed: AtomicU64

Total pages failed.

§findings_generated: AtomicU64

Total findings generated.

§bytes_fetched: AtomicU64

Total bytes fetched.

§fetch_time_us: AtomicU64

Total fetch time (microseconds).

§analysis_time_us: AtomicU64

Total analysis time (microseconds).

§storage_time_us: AtomicU64

Total storage write time (microseconds).

§active_connections: AtomicU64

Active connections.

§circuit_breaker_trips: AtomicU64

Total circuit breaker trips (transitions to Open state).

§resource_limit_hits: AtomicU64

Total resource limit hits.

§pages_skipped_circuit_breaker: AtomicU64

Pages skipped due to circuit breaker being open.

Implementations§

Source§

impl Metrics

Source

pub fn new() -> Self

Create new metrics instance.

Source

pub fn record_page_success( &self, bytes: u64, fetch_us: u64, analysis_us: u64, storage_us: u64, findings: u64, )

Record a successful page crawl.

Source

pub fn record_page_failure(&self)

Record a failed page crawl.

Source

pub fn record_circuit_breaker_trip(&self)

Record a circuit breaker trip (transition to Open state).

Source

pub fn record_resource_limit_hit(&self)

Record a resource limit being hit.

Source

pub fn record_page_skipped_circuit_breaker(&self)

Record a page skipped because the circuit breaker was open.

Source

pub fn inc_connections(&self)

Increment active connections.

Source

pub fn dec_connections(&self)

Decrement active connections. Uses fetch_update to prevent underflow below zero.

Source

pub fn pages_per_second(&self, elapsed: Duration) -> f64

Get pages per second.

Source

pub fn avg_fetch_time_ms(&self) -> f64

Get average fetch time in milliseconds.

Source

pub fn avg_analysis_time_ms(&self) -> f64

Get average analysis time in milliseconds.

Source

pub fn throughput_bps(&self, elapsed: Duration) -> f64

Get total throughput (bytes per second).

Source

pub fn snapshot(&self) -> MetricsSnapshot

Get snapshot of all metrics.

Source

pub fn reset(&self)

Reset all metrics.

Trait Implementations§

Source§

impl Default for Metrics

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<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