Struct InMemoryBackend

Source
pub struct InMemoryBackend { /* private fields */ }
Expand description

High-performance in-memory metrics backend using RwLock

This implementation provides:

  • Thread-safe concurrent access (multiple readers, single writer)
  • O(1) average case lookup and insertion
  • Memory-efficient storage
  • Lock-free reads when possible

Implementations§

Source§

impl InMemoryBackend

Source

pub fn new() -> Self

Create a new in-memory backend

Source

pub fn with_capacity(capacity: usize) -> Self

Create a new in-memory backend with initial capacity

Source

pub fn get_stats(&self) -> BackendStats

Get statistics about this backend

Source

pub fn get_metrics_by_namespace(&self, namespace: &str) -> Vec<Metric>

Get metrics by namespace

Source

pub fn get_metrics_by_type(&self, metric_type: MetricType) -> Vec<Metric>

Get metrics by type

Source

pub fn put_metrics(&self, metrics: Vec<Metric>) -> MetricsResult<()>

Bulk insert metrics (more efficient than individual puts)

Source

pub fn remove_metrics_by_namespace( &self, namespace: &str, ) -> MetricsResult<usize>

Remove metrics by namespace

Trait Implementations§

Source§

impl Debug for InMemoryBackend

Source§

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

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

impl Default for InMemoryBackend

Source§

fn default() -> Self

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

impl MetricsBackend for InMemoryBackend

Source§

fn as_any(&self) -> &dyn Any

Get a reference to this object as Any for downcasting
Source§

fn put_metric(&self, metric: Metric) -> MetricsResult<()>

Store or update a metric
Source§

fn get_metric(&self, id: &MetricId) -> MetricsResult<Metric>

Retrieve a metric by ID
Source§

fn contains_metric(&self, id: &MetricId) -> bool

Check if a metric exists
Source§

fn remove_metric(&self, id: &MetricId) -> MetricsResult<()>

Remove a metric
Source§

fn list_metric_ids(&self) -> Vec<MetricId>

Get all metric IDs currently stored
Source§

fn list_all_metrics(&self) -> Vec<Metric>

Get all metrics (potentially expensive operation)
Source§

fn clear_all(&self) -> MetricsResult<()>

Clear all metrics
Source§

fn metric_count(&self) -> usize

Get the number of metrics stored
Source§

fn increment_counter(&self, id: &MetricId, delta: u64) -> MetricsResult<u64>

Increment a counter by the given amount
Source§

fn set_gauge(&self, id: &MetricId, value: f64) -> MetricsResult<()>

Set a gauge value
Source§

fn record_histogram_sample( &self, id: &MetricId, sample: f64, ) -> MetricsResult<()>

Add a sample to a histogram

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, 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, 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.