Struct SimpleMetricManager

Source
pub struct SimpleMetricManager<H> { /* private fields */ }
Expand description

A MetricManager implementation that provides simple metric registration and handling.

SimpleMetricManager provides a simple way to manage metrics with support for command callbacks and metric publishing.

§Example

use srad_eon::SimpleMetricManager;

//Create a new simple metric manager
let manager = SimpleMetricManager::new();

// Assume we successfully create a device with a SimpleMetricManager as it's metrics manager
create_device_with_manager(&manager);

// Register a simple metric
let counter = manager.register_metric("Counter", 0 as i32).unwrap();

// Register a metric with a command handler
let temperature = manager.register_metric_with_cmd_handler(
    "temperature",
    25.5,
    |mgr, metric, new_value| async move {
        if let Some(value) = new_value {
          mgr.publish_metric(metric.update(|x|{ *x = value })).await;
        }
    }
);

Implementations§

Source§

impl<H> SimpleMetricManager<H>
where H: MetricPublisher + Clone + Send + Sync + 'static,

Source

pub fn new() -> Self

Creates a new empty SimpleMetricManager.

This initialises a new metric manager with no registered metrics.

Source

pub fn register_metric<S, T>( &self, name: S, value: T, ) -> Option<SimpleManagerMetric<T, H>>
where S: Into<String>, T: MetricValue + Clone + Send + 'static,

Registers a new metric with the given name and initial value.

Returns None if a metric with the same name already exists, otherwise returns the newly created metric.

Source

pub fn register_metric_with_cmd_handler<S, T, F, Fut>( &self, name: S, value: T, cmd_handler: F, ) -> Option<SimpleManagerMetric<T, H>>
where S: Into<String>, T: MetricValue + Clone + Send + 'static, F: Fn(SimpleMetricManager<H>, SimpleManagerMetric<T, H>, Option<T>) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,

Registers a new metric with a command handler that will be called when commands for this metric are received.

The command handler is an async function that receives the manager, the metric, and an optional new value for the metric. If the value is “None” that indicates the CMD metric ‘is_null’ field was true

Returns None if a metric with the same name already exists, otherwise returns the newly created metric.

Source

pub async fn publish_metric( &self, metric: SimpleManagerPublishMetric, ) -> Result<(), PublishError>

Publishes a single metric.

Returns an error if the metric was not published.

Source

pub async fn publish_metrics( &self, metrics: Vec<SimpleManagerPublishMetric>, ) -> Result<(), PublishError>

Publishes a multiple metric in a single batch.

Returns an error if the metrics were not published.

Trait Implementations§

Source§

impl<H: Clone> Clone for SimpleMetricManager<H>

Source§

fn clone(&self) -> SimpleMetricManager<H>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<H> Default for SimpleMetricManager<H>
where H: MetricPublisher + Clone + Send + Sync + 'static,

Source§

fn default() -> Self

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

impl DeviceMetricManager for SimpleMetricManager<DeviceHandle>

Source§

fn init(&self, handle: &DeviceHandle)

Initialise the struct. Read more
Source§

fn on_dcmd<'life0, 'async_trait>( &'life0 self, __arg1: DeviceHandle, metrics: MessageMetrics, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Processes DCMD metrics. Read more
Source§

impl<H> MetricManager for SimpleMetricManager<H>

Source§

fn initialise_birth(&self, bi: &mut BirthInitializer)

Initialises the set of metrics to be included in a birth or rebirth message. Read more
Source§

impl NodeMetricManager for SimpleMetricManager<NodeHandle>

Source§

fn init(&self, handle: &NodeHandle)

Initialise the struct. Read more
Source§

fn on_ncmd<'life0, 'async_trait>( &'life0 self, __arg1: NodeHandle, metrics: MessageMetrics, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Processes NCMD metrics. 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.