Skip to main content

IMoBroService

Service that allows the plugin to interact with MoBro in order to register items, update metric values, etc.

info

All item registrations (metrics, categories, ...) as well as metric value updates are accumulated and then pushed to the MoBro data service in bulk, latest after 100 ms.

Functions

Register(IEnumerable<IMoBroItem>)

Registers new items with the service

Parameters

NameTypeDescription
itemsIEnumerable<IMoBroItem>The items to register

Example

IEnumerable<IMoBroItem> metrics = CreateMetrics();
_mobro.Register(metrics);

Register(IMoBroItem)

Registers a new item with the service

Parameters

NameTypeDescription
itemIMoBroItemThe item to register

Example

var metric = MoBroItem
.CreateMetric()
.WithId("os_name")
...
.Build();

_mobro.Register(metric);

Unregister(IEnumerable<string>)

Unregister items with the service

Parameters

NameTypeDescription
idsIEnumerable<string>The ids of the items to unregister

Example

_mobro.Unregister(new string[] {"os_name","cpu_usage"});

Unregister(string)

Unregister an item with the service

Parameters

NameTypeDescription
idstringThe id of the item to unregister

Example

_mobro.Unregister("os_name");

TryGet<T>(string, out T): T

Gets the registered item associated with the specified id

Types

  • T: The type of the item

Parameters

NameTypeDescription
idstringThe id of the item to get
itemT (out)When this method returns, contains the registered item associated with the specified id; otherwise null

Returns

true if an item with the given id and type is registered; otherwise false

Example

if (_mobro.TryGet<Metric>("os_name", out var metric))
{
Console.WriteLine($"Metric: {metric.Label}");
}
else
{
// metric with id 'os_name' not registered
}

ClearRegistration

Clears (=unregisters) all currently registered items

Example

_mobro.ClearRegistration();

UpdateMetricValues(IEnumerable<MetricValue>)

Push a new values for one or more registered metrics

Parameters

NameTypeDescription
valuesIEnumerable<MetricValue>The metric values

Example

IEnumerable<MetricValue> metricValues = GetCurrentValues();
_mobro.UpdateMetric(metricValues);

UpdateMetricValue(string, object?, DateTime)

Push a new value for a registered metric

Parameters

NameTypeDescription
idstringThe id of the metric
valueobject?The new value of the metric
timestampDateTimeThe date and time the value was recorded or measured at

Example

_mobro.UpdateMetric("os_name", "Windows 11", DateTime.UtcNow);

UpdateMetricValue(string, object?)

Push a new value for a registered metric with the timestamp automatically set to DateTime.UtcNow

Parameters

NameTypeDescription
idstringThe id of the metric
valueobject?The new value of the metric

Example

_mobro.UpdateMetric("os_name", "Windows 11");

UpdateMetricValue(MetricValue)

Push a new value for a registered metric

Parameters

NameTypeDescription
valueMetricValueThe MetricValue

Example

_mobro.UpdateMetric(new MetricValue(
"os_name",
DateTime.UtcNow,
"Windows 11"
));

GetMetricValue(string): MetricValue

Gets the current value assigned to the metric with the specified id

Parameters

NameTypeDescription
idstringThe id of the metric

Returns

The MetricValue currently assigned to the metric

Example

var metricValue = _mobro.GetMetricValue("os_name");
Console.WriteLine($"Current OS: {metricValue.Value}");

Error(string)

Notifies the service that an unrecoverable error has occurred
This will cause the service to terminate the plugin

Parameters

NameTypeDescription
messagestringThe error message

Example

_mobro.Error("Plugin error");

Error(Exception)

Notifies the service that an unrecoverable error has occurred
This will cause the service to terminate the plugin

Parameters

NameTypeDescription
exceptionExceptionThe occurred exception

Example

try {
// some logic
}
catch(Exception e)
{
_logger.Error(e, "Plugin error");
_mobro.Error(e);
}