[#BloombergLP-balm-MetricsManager] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/balm.adoc[balm]::MetricsManager :relfileprefix: ../../ :mrdocs: This class implements a manager for the recording and publishing of metrics. Metrics managed by a `MetricsManager` are grouped into categories identified by a string. The metrics manager allows clients to register a `Publisher` object using the `addGeneralPublisher` and `addSpecificPublisher` operations. Metrics can be recorded in one of two ways: Clients can (1) implement their own metric collection facilities and register a callback using this metric manager's `registerMetricsCallback` method; or (2) use the `Collector` objects available from the `CollectorRepository` owned by this metrics manager. == Synopsis Declared in `<balm_metricsmanager.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class MetricsManager; ---- == Type Aliases [cols="1,4"] |=== | Name| Description | xref:BloombergLP/balm/MetricsManager/CallbackHandle.adoc[`CallbackHandle`] | Identifies a registered `RecordsCollectionCallback`. | xref:BloombergLP/balm/MetricsManager/RecordsCollectionCallback.adoc[`RecordsCollectionCallback`] | `RecordsCollectionCallback` is an alias for a callback function that appends to the supplied `MetricRecord` vector the values of the collected metrics, and, if the provided `bool` is `true`, resets those metrics to their default values. Clients can register callbacks matching this prototype with the metrics manager. Here is an example prototype matching this callback: ` void collectionCb(bsl::vector<MetricRecord> *records, bool resetFlag); ` |=== == Enums [cols="1,4"] |=== | Name| Description | xref:BloombergLP/balm/MetricsManager/_04enum.adoc[`Unnamed enum`] | Callback handle constants. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/balm/MetricsManager/2constructor.adoc[`MetricsManager`] [.small]#[constructor]# | Create a `MetricsManager`. Optionally specify a `basicAllocator` used to supply memory. If `basicAllocator` is 0, the currently installed default allocator is used. | xref:BloombergLP/balm/MetricsManager/2destructor.adoc[`~MetricsManager`] [.small]#[destructor]# | Destroy this `MetricsManager`. | xref:BloombergLP/balm/MetricsManager/addGeneralPublisher.adoc[`addGeneralPublisher`] | Add the specified `publisher` to the set of publishers that will be used to propagate records for _every_ category published by this metrics manager. Return 0 on success, and a non‐zero value with no effect if `publisher` has already been registered. After this method returns, _any_ category published by this metrics manager will be published to `publisher`. Note that this method will have no effect and return a non‐zero value if `publisher` was previously registered for one or more specific categories (using the alternative `addSpecificPublisher` method). | xref:BloombergLP/balm/MetricsManager/addSpecificPublisher-06.adoc[`addSpecificPublisher`] | `addSpecificPublisher` overloads | xref:BloombergLP/balm/MetricsManager/collectSample-0c.adoc[`collectSample`] | `collectSample` overloads | xref:BloombergLP/balm/MetricsManager/collectorRepository-077.adoc[`collectorRepository`] | `collectorRepository` overloads | xref:BloombergLP/balm/MetricsManager/findGeneralPublishers-09.adoc[`findGeneralPublishers`] | `findGeneralPublishers` overloads | xref:BloombergLP/balm/MetricsManager/findSpecificPublishers-02.adoc[`findSpecificPublishers`] | `findSpecificPublishers` overloads | xref:BloombergLP/balm/MetricsManager/metricRegistry-0f.adoc[`metricRegistry`] | `metricRegistry` overloads | xref:BloombergLP/balm/MetricsManager/publish-028.adoc[`publish`] | `publish` overloads | xref:BloombergLP/balm/MetricsManager/publishAll-027.adoc[`publishAll`] | `publishAll` overloads | xref:BloombergLP/balm/MetricsManager/registerCollectionCallback-0a.adoc[`registerCollectionCallback`] | `registerCollectionCallback` overloads | xref:BloombergLP/balm/MetricsManager/removeCollectionCallback.adoc[`removeCollectionCallback`] | Remove the callback associated with the specified `handle`. Return 0 on success, or a non‐zero value if `handle` cannot be found. | xref:BloombergLP/balm/MetricsManager/removePublisher-099.adoc[`removePublisher`] | `removePublisher` overloads | xref:BloombergLP/balm/MetricsManager/setAllCategoriesEnabled.adoc[`setAllCategoriesEnabled`] | Set whether each category currently registered with `metricRegistry()` is enabled to the specified `value`, and ensure that categories registered after this call are initialized as either enabled or disabled, accordingly. If a category is disabled it will not be published (see the `publish` methods), and higher level components may not record values for metrics belonging to the category (for an example, see the `balm_metric` documentation). This operation is logically equivalent to iterating over the list of categories currently registered with `metricRegistry()` and calling `setCategoryEnabled` on each category individually, and also setting a default `isEnabled()` value (for newly‐created categories). Hence, subsequent calls to `setCategoryEnabled` will override this value for a particular category. Note that this operation is thread‐safe, but _not_ atomic: Other threads may simultaneously access the current enabled status for a category while this operation completes. Also note that this operation has _linear_ runtime performance with respect to the total number of category holders registered with `metricRegistry()` (see `balm_metricregistry` and `balm_category` for information on category holders). | xref:BloombergLP/balm/MetricsManager/setCategoryEnabled-0c.adoc[`setCategoryEnabled`] | `setCategoryEnabled` overloads | xref:BloombergLP/balm/MetricsManager/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<MetricsManager, UsesBslmaAllocator>`] | Declare that this type uses a `bslma` allocator. |=== == Friends [cols="1,4"] |=== | Name| Description | `xref:BloombergLP/balm/MetricsManager_PublicationHelper.adoc[BloombergLP::balm::MetricsManager_PublicationHelper]` | defined in implementation |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#