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:

Table 3 Configuration Structure

Path

Type

Description

Default Value

/counter_poll_interval_ms

RtcInt64

Interval in milliseconds between polling all registered counters for current value and writing them to OLDB.

5000

/thread_poll_interval_ms

RtcInt64

Interval in milliseconds between polling all registered threads for current statistics and writing them to OLDB.

5000

/monitor_thread_nice

RtcInt64

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.

Table 4 OLDB structure

Path

Description

/counter

All registered counters are located under this path.

/counter/<id>

Each counter is organized using the counter identity provided when registering the counter.

/counter/<id>/description

Contains the description provided when registering the counter.

/counter/<id>/value

Current scalar value of the counter.

/thread

All registered thread are located under this path.

/thread/<id>

Each thread is organized using the thread identity provided when registering the thread.

/thread/<id>/description

Contains the description provided when registering the thread.

/thread/<id>/pid

Contains the thread pid_t value.

/thread/<id>/sched

Contains the content of procfs task sched file.

/thread/<id>/status

Contains the content of procfs task status file.

Supported Performance Counter Types

ComponentMetrics supports the following counter types:

Table 5 Supported Counter Types

perfc Type

Value Type

perfc::CounterDouble

double

perfc::CounterU64

uint64_t

perfc::CounterI64

int64_t