BDE 4.14.0 Production release
Loading...
Searching...
No Matches
balm_bdlmmetricsadapter

Detailed Description

Outline

Purpose

Provide a concrete instance of the bdlm metrics adapter.

Classes

Description

This component provides a concrete instance, balm::BdlmMetricsAdapter, of the bdlm::MetricsAdapter protocol, enabling registration of metric collection callbacks with a provided balm::MetricsManager. balm::BdlmMetricsAdapter also provides methods to aid in population of default bdlm::MetricDescriptor attribute values.

Thread Safety

This class is thread-aware (see {bsldoc_glossary |Thread-Aware}).

Usage

This section illustrates intended use of this component.

Example 1: Using balm::BdlmMetricsAdapter

This example demonstrates the initialization and usage of the balm::BdlmMetricsAdapter object, allowing for registering metric callback functions with the balm monitoring system.

First, we provide a metric function to be used during callback registration with the balm monitoring system:

void elidedMetric(BloombergLP::bdlm::Metric *value)
{
(void)value;
// ...
}

Then, we construct a balm::MetricsManager object and use it to construct a balm::BdlmMetricsAdapter that will use "bdlm" as its default metric namespace, "svc" as its default object indentifier prefix, and will not attempt to set itself as the default metrics adapter:

balm::BdlmMetricsAdapter adapter(&manager, "bdlm", "svc");
Definition balm_bdlmmetricsadapter.h:153
Definition balm_metricsmanager.h:490

Next, we construct a bdlm::MetricsDescriptor object to be used when registering the callback function, using constants from bdlm::MetricDescriptor for the namespace and identifier to indicate the implementation of the bdlm::MetricsAdapter protocol should supply values:

"example",
1,
"balm.bdlmmetricsadapter",
"bmr",
Definition bdlm_metricdescriptor.h:142
static const char * k_USE_METRICS_ADAPTER_NAMESPACE_SELECTION
Definition bdlm_metricdescriptor.h:170
static const char * k_USE_METRICS_ADAPTER_OBJECT_ID_SELECTION
Definition bdlm_metricdescriptor.h:171

Now, we register the collection callback:

adapter.registerCollectionCallback(descriptor,
elidedMetric);
int CallbackHandle
Definition bdlm_metricsadapter.h:297

Finally, presumably during shutdown of the application, we remove the callback from the monitoring system, and verify the callback was successfully removed:

assert(0 == adapter.removeCollectionCallback(handle));