Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component balm_collectorrepository
[Package balm]

Provide a repository for collectors. More...

Namespaces

namespace  balm

Detailed Description

Outline
Purpose:
Provide a repository for collectors.
Classes:
balm::CollectorRepository a repository for collectors
See also:
Component balm_collector, Component balm_integercollector, Component 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:
  bslma::Allocator *allocator = bslma::Default::allocator(0);
  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"));
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);
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.
  bsl::vector<balm::MetricRecord> records(allocator);
  repository.collectAndReset(&records, metricRegistry.getCategory("Test"));
      assert(4 == records.size());
Finally we write the recorded values to the console:
  bsl::vector<balm::MetricRecord>::const_iterator it;
  for (it = records.begin(); it != records.end(); ++it) {
       bsl::cout << *it << bsl::endl;
  }
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 ]