Component Metrics
rtctk::componentFramework::ComponentMetricsIf is a service accessible in the component framework
service container and allows registration of performance counters from the perfc library
which then acts as a source of metrics that is published to Online Database.
Usage
First get access to the service instance from the component framework service container:
#include <rtctk/componentFramework/componentMetricsIf.hpp>
using rtctk::componentFramework::ComponentMetricsIf;
ComponentMetricsIf& metrics = m_services.Get<ComponentMetricsIf>();
Then counters can be registered:
#include <rtctk/componentFramework/componentMetricsIf.hpp>
using rtctk::componentFramework::CounterMetricInfo;
perfc::DoubleCounter counter;
// Register the double counter providing an id and description.
// It will be automatically unregistered if `reg` is deleted.
//
// note: It's critical to unregister the counter before it is destroyed otherwise
// the ComponentMetricsIf may access invalid memory and cause segfault. Easiest
// is normally to tie the lifetime of the registration together with the counter
// (with registration being destroyed before counter).
perfc::ScopedRegistration reg = metrics.AddCounter(
&counter,
CounterMetricInfo("my_counter", "Example counter for demo purposes"));
// ...
// Keep updating counter with changes which will then be reflected in OLDB
// eventually.
counter.Store(123.4);
After registering the counter, the Component Metrics will have created corresponding datapoints
in OLDB. If the component instance is e.g. called example the path will be:
/example/metrics/counter/my_counter
Configuration
The component metrics service comes with a reasonable default configuration. In case the defaults need to be adjusted, the service can be re-configured from the runtime repository using dynamic parameters.
These optional parameters are all organized under root path /<component-name>/dynamic/metrics
which is represented by the leading / in the paths below:
Path |
Type |
Description |
Default Value |
|---|---|---|---|
|
|
Interval in milliseconds between polling all registered counters for current value and writing them to OLDB. |
5000 |
|
|
Thread nice value (-19 - 20) applied to the monitoring thread. This is mainly used to set a lower priority (higher nice value). |
5 |
To enable this, the service provides public method ComponentMetricsIf::UpdateParams that pulls
the config parameters from the runtime repository and applies them. In custom components, this
method can be hooked into the initialising and updating activity methods of the business logic.
Online Database Data Points
The following describes the structure of the data points written by the Component Metrics service.
All paths are components under the root path /<component-name>/metrics referred to
simply as the leading / in the table.
The <id> in the paths seen in the table refers to the ID parameter passed to the
CounterMetricInfo constructor.
Path |
Description |
|---|---|
|
All registered counters are located under this path. |
|
Current scalar value of the counter. Description will be added as metadata in the future. |
Supported Performance Counter Types
ComponentMetrics supports the following counter types:
|
Value Type |
|---|---|
|
|
|
|
|
|