BDE 4.14.0 Production release
|
Modules | |
balm_bdlmmetricsadapter | |
Provide a concrete instance of the bdlm metrics adapter. | |
balm_category | |
Provide a representation of a metric category. | |
balm_collector | |
Provide a container for collecting and aggregating metric values. | |
balm_collectorrepository | |
Provide a repository for collectors. | |
balm_configurationutil | |
Provide a namespace for metrics configuration utilities. | |
balm_defaultmetricsmanager | |
Provide for a default instance of the metrics manager. | |
balm_integercollector | |
Provide a container for collecting integral metric values. | |
balm_integermetric | |
Provide helper classes for recording int metric values. | |
balm_metric | |
Provide helper classes for recording metric values. | |
balm_metricdescription | |
Provide a description for a metric. | |
balm_metricformat | |
Provide a formatting specification for a metric. | |
balm_metricid | |
Provide an identifier for a metric. | |
balm_metricrecord | |
Provide an aggregated record of the value of a metric. | |
balm_metricregistry | |
Provide a registry for metrics. | |
balm_metrics | |
Provide a suite of operations for recording metric values. | |
balm_metricsample | |
Provide a container for a sample of collected metric records. | |
balm_metricsmanager | |
Provide a manager for recording and publishing metric data. | |
balm_publicationscheduler | |
Provide a scheduler for publishing metrics. | |
balm_publicationtype | |
Provide an enumeration of aggregate types used to publish metrics. | |
balm_publisher | |
Provide a protocol to publish recorded metric values. | |
balm_stopwatchscopedguard | |
Provide a scoped guard for recording elapsed time. | |
balm_streampublisher | |
Provide a balm::Publisher implementation that writes to a stream. | |
Provide thread-safe collection and publishing of metrics.
Basic Application Library Metrics (balm)
The 'balm' package provides facilities for recording and publishing metric data.
Bloomberg internal software should also consider the GUTS telemetry API, which is integrated into Bloomberg infrastructure.
A "metric", in the context of this package, is a measured event. This package does not define what constitutes an event or what the associated measurement represents. For example, a metric could record the elapsed time of a function call (in which case the event is the function call, and the measured value is the elapsed time), or a metric could record the number of requests received by a service (in which case the event is the reception of a request, and the measured value is 1).
This package provides components for collecting and aggregating measurement values (see balm_metric and balm_metrics ). Those aggregated metric measurements are described by a metric record (see balm_metricrecord ), which contains the identifier for the recorded metric, the number of times the event occurred, as well as the minimum, maximum, and total of the measured values. This package provides a protocol for publishing metric records (see balm_publisher ) and an implementation of that protocol for publishing records to a stream (see 'balm_streampublisher). Finally this package provides a balm_metricsmanager component to coordinate the collection and publication of metrics.
The 'balm' package currently has 22 components having 13 levels of physical dependency. The list below shows the hierarchical ordering of the components. The order of components within each level is not architecturally significant, just alphabetical.
balm_bdlmmetricsadapter : Provide a concrete instance of the bdlm
metrics adapter.
balm_category : Provide a representation of a metric category.
balm_collector : Provide a container for collecting and aggregating metric values.
balm_collectorrepository : Provide a repository for collectors.
balm_configurationutil : Provide a namespace for metrics configuration utilities.
balm_defaultmetricsmanager : Provide for a default instance of the metrics manager.
balm_integercollector : Provide a container for collecting integral metric values.
balm_integermetric : Provide helper classes for recording int metric values.
balm_metric : Provide helper classes for recording metric values.
balm_metricdescription : Provide a description for a metric.
balm_metricformat : Provide a formatting specification for a metric.
balm_metricid : Provide an identifier for a metric.
balm_metricrecord : Provide an aggregated record of the value of a metric.
balm_metricregistry : Provide a registry for metrics.
balm_metrics : Provide a suite of operations for recording metric values.
balm_metricsample : Provide a container for a sample of collected metric records.
balm_metricsmanager : Provide a manager for recording and publishing metric data.
balm_publicationscheduler : Provide a scheduler for publishing metrics.
balm_publicationtype : Provide an enumeration of aggregate types used to publish metrics.
balm_publisher : Provide a protocol to publish recorded metric values.
balm_stopwatchscopedguard : Provide a scoped guard for recording elapsed time.
balm_streampublisher : Provide a balm::Publisher
implementation that writes to a stream.
The following section presents a simple example of collecting metrics. We create a trivial application that reads lines of text from standard input and counts the number of letters, words, and unique words in each line. The function 'processLine()' processes each line of text and records metrics for the number of times 'processLine()' has been called, the elapsed time for the calls to 'processLine()', the total character count, and the total word count.
Before we can collect metrics we must first create a 'balm_MetricsManager' object to manage their collection (and publication). We use the 'balm_DefaultMetricsManager', which is a singleton instance of the 'balm_MetricsManager' class. The default metrics manager is used by the collection macros that we will use to collect metrics (see balm_metrics ). Note that the default metrics manager is intended to be created and destroyed by the owner of 'main'. A default metrics manager instance should be created during the initialization of an application (while the task has a single thread) and destroyed just prior to termination (when there is, similarly, a single thread).
We create a 'balm_DefaultMetricsManagerScopedGuard', which manages the lifetime of the default metrics manager (singleton) instance. At construction, we provide the scoped guard an output stream ('stdout') to which the balm_publisher (created by the default metrics manager) will publish metrics.
We create a 'balm_PublicationScheduler' to periodically publish the metrics we have collected. A 'balm_PublicationScheduler' invokes 'publish()' on the supplied 'balm_MetricsManager' object according to the provided schedule.
To begin periodically publishing metrics we 'start' the event scheduler supplied to the 'balm_PublicationScheduler', and then set a simple schedule to publish all collected metrics every 30 seconds.
Finally we have our main "application" loop, which reads lines of text from the standard input (until "exit" is provided as input) and calls 'processLine()' for each line of input.
At the end of this lexical scope 'managerGuard' is destroyed, releasing the default 'balm_MetricsManager' instance.
Next we define the 'processLine()' function. The 'processLine()' function "processes" a line of text, and collects several metrics related to the function invocation.
Increment the count of the number of calls to 'processLine()' and use the 'BALM_METRICS_TIME_BLOCK' macro (see balm_metrics ) to collect the elapsed time of this function call. Note that all the metrics recorded by this function belong to the (arbitrarily chosen) category "Example".
Once we've "processed" the 'line', update the character count and word count metrics.
We've now created our example application. A typical session with this application might look like (note that '>' indicates user input):
Every 30 seconds metrics will be reported to standard output. A typical publication of metrics would look like:
This section provides a brief summary of the features of the 'balm' package - details can be found in the indicated components and later in this document.
The components provided by the 'balm' package were designed for use in multi-threaded applications. Metrics can be safely collected and published simultaneously from multiple threads. Nevertheless, not every individual component in the 'balm' package is thread-safe. See the individual component documentation for more information.
The 'balm' package defines several ways to collect metrics, as well as allowing users to define their own collection mechanisms.
The balm_metric and balm_integermetric components both define macros and helper classes for recording metrics. The mechanisms in balm_integermetric are slightly more efficient for collecting integral metric values, but are otherwise identical.
The macros and classes defined by the balm_metric , balm_integermetric and balm_metrics components provide the same basic functionality. Clients may find the 'balm_Metric' or 'balm_IntegerMetric' classes better suited to collecting metrics associated with a particular instance of a stateful object, while the 'BALM_METRICS_*' macros are better suited to collecting metrics associated with a particular code path (rather than an object instance). In most instances, however, choosing between the two is a matter of taste.
The 'balm' package allows users to define their own metric collection mechanisms by registering a callback with a 'balm_MetricsManager' object. User defined callbacks must match the 'balm_MetricsManager::MetricsCollectionCallback' function signature and collect metrics for a single category. Every time 'publish' is invoked for a category, the metrics manager will invoke the registered collection callbacks for that category, and publish the collected metrics. See balm_metricsmanager for more information.
The balm_publisher component defines a protocol for publishing metric records. Users can register publisher objects with a metrics manager. Invoking 'publish()' on a metrics manager will collect metrics for the set of categories supplied with the function call, and then publish the metrics for each supplied category to publishers registered for that category.
The 'balm_StreamPublisher' class implements the 'balm_Publisher' protocol to provide a default publisher for publishing metrics to a stream.
Users can schedule the periodic publication of metrics using the balm_publicationscheduler component. In the example presented above, under "Getting Started", a 'balm_PublicationScheduler' object was configured to publish all categories of metrics metrics every 30 seconds.
At construction, a 'balm_PublicationScheduler' object is provided the addresses of a 'balm_MetricsManager' and a 'bcep_TimerEventScheduler'. Users can call 'scheduleCategory()' to schedule an individual metric category to be published repeatedly at a given interval, or call 'setDefaultSchedule()' to schedule the publication of any category not given an individual schedule. At the end of a scheduled time interval, the publication scheduler invokes the metrics manager's 'publish()' operation with the set of categories to publish. Note that, the publication scheduler will combine categories that occur at the same frequency into a single invocation of the metrics manager's 'publish' operation.
Users can disable (and re-enable) a category of metrics by calling 'balm_MetricsManager::setCategoryEnabled' method. A disabled category will not be published by the metrics manager. In addition, the balm_metric , balm_integermetric , balm_metrics , and balm_stopwatchscopedguard components will not collect metrics for disabled categories (minimizing the performance cost of collecting metric for disabled categories). Note that when 'balm_MetricsManager::publish()' is called on a disabled category, the metrics manager will invoke any user defined collection callbacks registered for the disable category, but will not publish the collected metrics. Users defining their own metrics collection mechanism (using a 'balm_MetricsManager::MetricsCollectionCallback') must (manually) test whether a category is disabled if they wish to avoid collecting metrics for a disabled category.