SimpleMetricManager

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, SimpleMetricBuilder};

//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(SimpleMetricBuilder::new("Counter", 0 as i32)).unwrap();

// Register a metric with a command handler
let temperature = manager.register_metric(
    SimpleMetricBuilder::new("temperature", 25.5)
    .with_cmd_handler(
        |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<T>( &self, builder: SimpleMetricBuilder<T, H>, ) -> Option<SimpleManagerMetric<T, H>>
where T: MetricValue + Clone + Send + 'static,

Registers a new metric from the builders settings.

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

fn birth_update_template_registry( &self, _template_registry: &mut TemplateRegistry, )

Update the templates registered with the node. 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.