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>
impl<H> SimpleMetricManager<H>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty SimpleMetricManager.
This initialises a new metric manager with no registered metrics.
Sourcepub fn register_metric<T>(
&self,
builder: SimpleMetricBuilder<T, H>,
) -> Option<SimpleManagerMetric<T, H>>
pub fn register_metric<T>( &self, builder: SimpleMetricBuilder<T, H>, ) -> Option<SimpleManagerMetric<T, H>>
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.
Sourcepub async fn publish_metric(
&self,
metric: SimpleManagerPublishMetric,
) -> Result<(), PublishError>
pub async fn publish_metric( &self, metric: SimpleManagerPublishMetric, ) -> Result<(), PublishError>
Publishes a single metric.
Returns an error if the metric was not published.
Sourcepub async fn publish_metrics(
&self,
metrics: Vec<SimpleManagerPublishMetric>,
) -> Result<(), PublishError>
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>
impl<H: Clone> Clone for SimpleMetricManager<H>
Source§fn clone(&self) -> SimpleMetricManager<H>
fn clone(&self) -> SimpleMetricManager<H>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<H> Default for SimpleMetricManager<H>
impl<H> Default for SimpleMetricManager<H>
Source§impl DeviceMetricManager for SimpleMetricManager<DeviceHandle>
impl DeviceMetricManager for SimpleMetricManager<DeviceHandle>
Source§fn init(&self, handle: &DeviceHandle)
fn init(&self, handle: &DeviceHandle)
Initialise the struct. Read more
Source§impl<H> MetricManager for SimpleMetricManager<H>
impl<H> MetricManager for SimpleMetricManager<H>
Source§fn initialise_birth(&self, bi: &mut BirthInitializer)
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>
impl NodeMetricManager for SimpleMetricManager<NodeHandle>
Source§fn init(&self, handle: &NodeHandle)
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,
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,
)
fn birth_update_template_registry( &self, _template_registry: &mut TemplateRegistry, )
Update the templates registered with the node. Read more
Auto Trait Implementations§
impl<H> Freeze for SimpleMetricManager<H>
impl<H> RefUnwindSafe for SimpleMetricManager<H>
impl<H> Send for SimpleMetricManager<H>where
H: Send,
impl<H> Sync for SimpleMetricManager<H>where
H: Send,
impl<H> Unpin for SimpleMetricManager<H>
impl<H> UnwindSafe for SimpleMetricManager<H>
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
Mutably borrows from an owned value. Read more