IMoBroService
Service that allows the plugin to interact with MoBro in order to register items, update metric values, etc.
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
Name | Type | Description |
---|---|---|
items | IEnumerable<IMoBroItem> | The items to register |
Example
IEnumerable<IMoBroItem> metrics = CreateMetrics();
_mobro.Register(metrics);
Register(IMoBroItem)
Registers a new item with the service
Parameters
Name | Type | Description |
---|---|---|
item | IMoBroItem | The item to register |
Example
var metric = MoBroItem
.CreateMetric()
.WithId("os_name")
...
.Build();
_mobro.Register(metric);
Unregister(IEnumerable<string>)
Unregister items with the service
Parameters
Name | Type | Description |
---|---|---|
ids | IEnumerable<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
Name | Type | Description |
---|---|---|
id | string | The 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
Name | Type | Description |
---|---|---|
id | string | The id of the item to get |
item | T (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
Name | Type | Description |
---|---|---|
values | IEnumerable<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
Name | Type | Description |
---|---|---|
id | string | The id of the metric |
value | object? | The new value of the metric |
timestamp | DateTime | The 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
Name | Type | Description |
---|---|---|
id | string | The id of the metric |
value | object? | The new value of the metric |
Example
_mobro.UpdateMetric("os_name", "Windows 11");
UpdateMetricValue(MetricValue)
Push a new value for a registered metric
Parameters
Name | Type | Description |
---|---|---|
value | MetricValue | The 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
Name | Type | Description |
---|---|---|
id | string | The 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
Name | Type | Description |
---|---|---|
message | string | The 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
Name | Type | Description |
---|---|---|
exception | Exception | The occurred exception |
Example
try {
// some logic
}
catch(Exception e)
{
_logger.Error(e, "Plugin error");
_mobro.Error(e);
}