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

Detailed Description

Outline

Purpose

Provide a repository for collectors.

Classes

See also
balm_collector, balm_integercollector, balm_metricsmanager

Description

This component defines a class, balm::CollectorRepository, that serves as a repository for balm::Collector and balm::IntegerCollector objects. The collector repository supports operations to create and lookup collectors, as well as an operation to collect metric records from the collectors in the repository. Collectors are identified by a metric id, which uniquely identifies the metric for which they collect values. The getDefaultCollector (and getDefaultIntegerCollector) operations return the default collector (or integer collector) for the supplied metric. The addCollector (and addIntegerCollector) operations create and return a new collector (or integer collector) for the specified metric. Each collector instance can can safely collect values from multiple threads, however, the collector does use a mutex: Applications anticipating high contention for that lock can use addCollector (and addIntegerCollector) to obtain multiple collectors and thereby reduce contention. Finally, the collectAndReset operation collects and returns metric records from each of the collectors in the repository.

Alternative Systems for Telemetry

Bloomberg software may alternatively use the GUTS telemetry API, which is integrated into Bloomberg infrastructure.

Thread Safety

balm::CollectorRepository is fully thread-safe, meaning that all non-creator operations on a given instance can be safely invoked simultaneously from multiple threads.

Usage

The following example illustrates creating a balm::CollectorRepository, then looking up collectors in that repository, and finally collecting values from the repository. We start by creating a repository and looking up 2 collectors and 2 integer collectors:

balm::MetricRegistry metricRegistry(allocator);
balm::CollectorRepository repository(&metricRegistry, allocator);
balm::Collector *collector1 = repository.getDefaultCollector("Test", "C1");
balm::Collector *collector2 = repository.getDefaultCollector("Test", "C2");
balm::IntegerCollector *intCollector1 =
repository.getDefaultIntegerCollector("Test", "C3");
balm::IntegerCollector *intCollector2 =
repository.getDefaultIntegerCollector("Test", "C4");
assert(collector1 != collector2);
assert(collector1 == repository.getDefaultCollector("Test", "C1"));
assert(intCollector1 != intCollector2);
assert(intCollector1 ==
repository.getDefaultIntegerCollector("Test", "C3"));
Definition balm_collectorrepository.h:184
Definition balm_collector.h:152
Definition balm_integercollector.h:151
Definition balm_metricregistry.h:180
Definition bslma_allocator.h:457
static Allocator * allocator(Allocator *basicAllocator=0)
Definition bslma_default.h:897

We now update the values in those collectors:

collector1->update(1.0);
collector1->update(2.0);
collector2->update(4.0);
intCollector1->update(5);
intCollector2->update(6);
void update(double value)
Definition balm_collector.h:271
void update(int value)
Definition balm_integercollector.h:282

We can use the repository to collect recorded values from the collectors it manages. Since there are collectors for four metrics, there should be four recorded values. Note the order in which the records are returned is undefined.

repository.collectAndReset(&records, metricRegistry.getCategory("Test"));
assert(4 == records.size());
Definition bslstl_vector.h:1025

Finally we write the recorded values to the console:

for (it = records.begin(); it != records.end(); ++it) {
bsl::cout << *it << bsl::endl;
}
iterator end() BSLS_KEYWORD_NOEXCEPT
Definition bslstl_vector.h:2519
VALUE_TYPE const * const_iterator
Definition bslstl_vector.h:1058

The output of the for-loop should be:

[ Test.C1: 2 3 1 2 ]
[ Test.C2: 1 4 4 4 ]
[ Test.C3: 1 5 5 5 ]
[ Test.C4: 1 6 6 6 ]