[#BloombergLP-bdlm-MetricsRegistry]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdlm.adoc[bdlm]::MetricsRegistry
:relfileprefix: ../../
:mrdocs:

This class implements a mechanism that provides a registry of metrics that is transferable to implementations of the `bdlm&colon;&colon;MetricsAdapter` protocol&period; This class is _usually_ a singleton&period;

== Synopsis

Declared in `&lt;bdlm&lowbar;metricsregistry&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class MetricsRegistry;
----

== Type Aliases

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlm/MetricsRegistry/Callback.adoc[`Callback`] 
| This `typedef` is an alias for a metrics registration callback&period;
| xref:BloombergLP/bdlm/MetricsRegistry/CallbackHandle.adoc[`CallbackHandle`] 
| This `typedef` is an alias for a metrics registration callback handle&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlm/MetricsRegistry/2constructor.adoc[`MetricsRegistry`]         [.small]#[constructor]#
| Create a `MetricsRegistry` object that stores the information necessary to forward the registration and unregistration of metrics to an adapter supplied with `setMetricsRegistry`&period; Optionally specify a `basicAllocator` used to supply memory&period; If `basicAllocator` is 0, the currently installed default allocator is used&period;
| xref:BloombergLP/bdlm/MetricsRegistry/2destructor.adoc[`&#126;MetricsRegistry`] [.small]#[destructor]#
| Unregister all registered metrics and destroy this `MetricsRegistry` object&period;
| xref:BloombergLP/bdlm/MetricsRegistry/allocator.adoc[`allocator`] 
| Return the allocator used by this object to supply memory&period;
| xref:BloombergLP/bdlm/MetricsRegistry/disableMetricsCollection.adoc[`disableMetricsCollection`] 
| Disable metrics collection&period; If there is an associated metrics adapter, all the collection callbacks are unregistered from that adapter&period; The adapter remains associated with this registry&period; Collection callbacks registered with this registry are not registered with the associated adapter until metrics collections is enabled&period; Return 0 on success, and a non&hyphen;zero value otherwise&period; Metrics collection is enabled at construction of this registry&period;
| xref:BloombergLP/bdlm/MetricsRegistry/enableMetricsCollection.adoc[`enableMetricsCollection`] 
| Enable metrics collection&period; If there is an associated metrics adapter, all collection callbacks will be registered with the adapter&period; Return 0 on success, and non&hyphen;zero value otherwise&period; Metrics collection is enabled at construction of this registry&period;
| xref:BloombergLP/bdlm/MetricsRegistry/numRegisteredCollectionCallbacks.adoc[`numRegisteredCollectionCallbacks`] 
| Return the number of registered metrics collection callbacks&period;
| xref:BloombergLP/bdlm/MetricsRegistry/registerCollectionCallback.adoc[`registerCollectionCallback`] 
| Register the metric described by the specified `descriptor` and associate it with the specified `callback` to collect data from the metric, and load the specified `result` with a handle can be used later to unregister the metric&period; Return 0 on success, and a non&hyphen;zero value otherwise&period; After this operation completes, `result&hyphen;&gt;isRegistered()` will be `true`&period; The metric and associated callback remain registered with this registry until either the handle is unregistered or destroyed&period; When a `MetricsAdapter` is associated with this registry using `setMetricsAdapter`, this object registers all the registered metrics and callbacks with that adapter, and similarly unregisters them if the `MetricAdapter` is later disassociated with this registry (either on this objects destruction, or due to a call to `removeMetricsAdapter` or `setMetricsAdapter`)&period; Furthermore, metrics collection can be disable with `disableMetricsCollection` and enabled with `enableMetricsCollection`&period; In this way, a `MetricsRegistry` serves as an intermediary between users of `bdlm` that register metrics and the subsystem for collecting and publishing metrics being adapted by a concrete instance of `bdlm&colon;&colon;MetricAdapter`&period;
| xref:BloombergLP/bdlm/MetricsRegistry/removeMetricsAdapter.adoc[`removeMetricsAdapter`] 
| If the specified `adapter` is the currently associated adapter, remove all registered metrics from it and disassociate with this registry&period; Return 0 on success, and a non&hyphen;zero value otherwise&period; Note that this operation takes an `adapter` to disambiguate multiple, potentially concurrent, calls to this method and `setMetricsAdapter`&period;
| xref:BloombergLP/bdlm/MetricsRegistry/setMetricsAdapter.adoc[`setMetricsAdapter`] 
| Configure this metrics registry to register all metrics collection callbacks with the specified `adapter` when the registry has metrics collection enabled&period; This operation first, if there is already an associated metrics adapter, unregisters all the collection callbacks from that adapter, then registers the collection callbacks with the new `adapter` if metrics collection is enabled&period; Return 0 on success, and a non&hyphen;zero value otherwise&period;
| xref:BloombergLP/bdlm/MetricsRegistry/2conversion.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration&lt;MetricsRegistry, UsesBslmaAllocator&gt;`] 
| Declare that this type uses a `bslma` allocator&period;
|===


== Static Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bdlm/MetricsRegistry/defaultInstance.adoc[`defaultInstance`] 
| Return a non&hyphen;`const` reference to the metrics registry singleton&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
