Outline
Purpose
Provide an abstract interface for metrics registration mechanisms.
- Deprecated:
- This component is not ready for public use.
Classes
Description
This component provides the base-level protocol (pure abstract interface) class, bdlm::MetricsAdapter
, that serves as a ubiquitous vocabulary type for various metrics registration mechanisms. Clients of this abstract base class will typically accept a supplied metrics adapter (often at construction) and use its registerCollectionCallback
and removeCollectionCallback
methods to register a collection object with a monitoring mechanism and remove a collection object from monitoring, respectively.
The registerCollectionCallback
method supplies a metric descriptor and a collection callback to a monitoring system. Specific monitoring systems may adapt the provided metric descriptor attributes to their needs.
Thread Safety
This class is minimally thread-safe (see {bsldoc_glossary |Minimally Thread-Safe}).
Usage
This section illustrates intended use of this component.
Example 1: Implementing the bdlm::MetricsAdapter Protocol
This example demonstrates an elided concrete implementation of the bdlm::MetricsAdapter
protocol that allows for registering metric callback functions with a monitoring system.
First, we define the interface of a limited my_MetricsMonitor
class that allows only one metric collection function to be registered:
class my_MetricsMonitor {
public:
void update();
double value() const;
};
Definition bdlm_metric.h:77
int CallbackHandle
Definition bdlm_metricsadapter.h:297
Definition bslstl_string.h:1281
Forward declaration.
Definition bslstl_function.h:934
Then, we implement the functions:
{
d_name = name;
d_callback = callback;
return 1;
}
int my_MetricsMonitor::removeCallback(
{
(void)handle;
return 0;
}
void my_MetricsMonitor::update()
{
d_callback(&d_value);
}
{
return d_name;
}
double my_MetricsMonitor::value() const
{
return d_value.theGauge();
}
double Gauge
Definition bdlm_metric.h:81
Next, we define the implementation class of the bdlm::MetricsAdapter
protocol:
my_MetricsMonitor *d_monitor_p;
public:
my_MetricsAdapter(my_MetricsMonitor *monitor);
~my_MetricsAdapter();
const Callback& callback);
};
Definition bdlm_metricdescriptor.h:142
Definition bdlm_metricsadapter.h:293
virtual int removeCollectionCallback(const CallbackHandle &handle)=0
virtual CallbackHandle registerCollectionCallback(const MetricDescriptor &metricDescriptor, const Callback &callback)=0
Then, we implement the methods of myMetricsAdapter
:
my_MetricsAdapter::my_MetricsAdapter(my_MetricsMonitor *monitor)
: d_monitor_p(monitor)
{
}
my_MetricsAdapter::~my_MetricsAdapter()
{
}
my_MetricsAdapter::registerCollectionCallback(
const Callback& callback)
{
return d_monitor_p->registerCallback(name, callback);
}
int my_MetricsAdapter::removeCollectionCallback(
{
return d_monitor_p->removeCallback(handle);
}
const bsl::string & metricNamespace() const
Return the metricNamespace attribute.
Definition bdlm_metricdescriptor.h:406
const bsl::string & objectTypeAbbreviation() const
Return the objectTypeAbbreviation attribute.
Definition bdlm_metricdescriptor.h:418
const bsl::string & metricName() const
Return the metricName attribute.
Definition bdlm_metricdescriptor.h:400
const bsl::string & objectTypeName() const
Return the objectTypeName attribute.
Definition bdlm_metricdescriptor.h:424
const bsl::string & objectIdentifier() const
Return the objectIdentifier attribute.
Definition bdlm_metricdescriptor.h:412
Next, we provide the metric method, my_metric
, which will compute its invocation count:
void my_metric(BloombergLP::bdlm::Metric *value)
{
*value = value->theGauge() + 1.0;
}
Then, we instantiate a my_MetricsMonitor
and a myMetricsAdapter
:
my_MetricsMonitor monitor;
my_MetricsAdapter adapter(&monitor);
Next, we construct a bdlm::MetricDescriptor
, register the my_metric
method with the monitor
, and verify the monitor
has the expected name for the metric:
adapter.registerCollectionCallback(descriptor, my_metric);
assert(monitor.name() == "a.b.c.d.e");
Now, we invoke the update
method a few times:
monitor.update();
monitor.update();
monitor.update();
Finally, we verify the metric has the expected value:
assert(monitor.value() == 3.0);