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 and
threads (of type pid_t
not pthread_t
) which will 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 and threads can be registered:
#include <rtctk/componentFramework/componentMetricsIf.hpp>
using rtctk::componentFramework::CounterMetricInfo;
using rtctk::componentFramework::ThreadMetricInfo;
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);
// Add current thread providing it an id and description.
// If thread is destroyed it will automatically be unregistered so there is no
// registration object.
metrics.AddThread(numapp::thisThread::GetThreadId(),
ThreadMetricInfo("my_thread",
"Example description of thread.");
Component Metrics will, after registering counter and thread, have created data points in OLDB. If
the component instance is e.g. called example
the base paths are:
/example/metrics/default/counter/my_counter
/example/metrics/default/thread/my_thread
Configuration¶
The Component Metrics can be configured from the runtime repository using dynamic parameters. It will check for changes in intervals and apply changed parameters.
The parameters are all organized under the root path /<component-name>/dynamic/metrics/default
and 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 |
|
|
Interval in milliseconds between polling all registered threads for current statistics 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 |
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/default
referred to
simply as the leading /
in the table.
Path |
Description |
---|---|
|
All registered counters are located under this path. |
|
Each counter is organized using the counter identity provided when registering the counter. |
|
Contains the description provided when registering the counter. |
|
Current scalar value of the counter. |
|
All registered thread are located under this path. |
|
Each thread is organized using the thread identity provided when registering the thread. |
|
Contains the description provided when registering the thread. |
|
Contains the thread |
|
Contains the content of procfs task sched file. |
|
Contains the content of procfs task status file. |