BDE 4.14.0 Production release
|
Provide a namespace for metrics configuration utilities.
This component provides a set of utility functions for configuring metrics. The balm::ConfigurationUtil
struct
provides short-cuts for common configuration operations that are performed on other components in the balm
package.
Bloomberg software may alternatively use the GUTS telemetry API, which is integrated into Bloomberg infrastructure.
balm::ConfigurationUtil
is fully thread-safe, meaning that all the methods can be safely invoked simultaneously from multiple threads.
This section illustrates intended use of this component.
This example uses balm::ConfigurationUtil
to configure the output for a metric.
We start by initializing a default metrics manager by creating a balm::DefaultMetricsManagerScopedGuard
, which manages the lifetime of the default metrics manager object. At construction, we provide the scoped guard an output stream (stdout
) to which the default metrics manager will publish metrics. Note that the default metrics manager is intended to be created and destroyed by the owner of main
. A metrics manager 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).
Next we create a metric, "avgElapsedTimeMs", that will output the average time, in milliseconds, spent in a section of code. We set the preferred publication type for the metric to be average:
Next, because we will record the elapsed time in seconds, we configure a format to scale the elapsed time by 1000.0:
We now collect an example value of .005:
Finally, we publish the metric. Note that in practice, clients of the balm
package can use the balm::PublicationScheduler
to schedule the periodic publication of metrics:
The output for the publication will look like:
In the following example we configure, using balm::ConfigurationUtil
, application-specific publication thresholds for a series of metrics. We will create an application-specific publisher that will use the configured thresholds to determine whether a metric should be written to the console. For simplicity, the metric thresholds in this example will be a single unsigned integer value that will be compared with the metric's total.
We start by defining an application-specific publisher implementation. This implementation is supplied a user data key on construction, which it uses to look up the threshold for a particular metric. If a metric's total value is greater than its threshold, it will log the metric to the console.
We now use the user data key to lookup the address of the threshold value. If this address is 0, no threshold is specified for the metric.
Now we examine how to configure a metrics manager with a ThresholdPublisher
, and set the thresholds for a couple of metrics. We start by defining a couple of threshold constants for our metrics:
Now, we configure a default metrics manager and publish a couple of example metrics. We start by initializing a default metrics manager by creating a balm::DefaultMetricsManagerScopedGuard
, which manages the lifetime of the default metrics manager:
Now we create a user data key for our threshold information:
Next we create an object of our application-specific publisher type, ThresholdPublisher
, and configure the default metrics manager to publish metrics using this publisher:
Next we configure two metric thresholds:
Now we update the value of a couple of metrics. Note that the recorded number of requests is greater than the metric's configured threshold:
Finally, we publish the collected metrics. Note that in practice, clients of the balm
package can use the balm::PublicationScheduler
to schedule the periodic publication of metrics:
The console output of the call to publishAll
will look like: