#include <userver/utils/statistics/storage.hpp>
Storage of metrics, usually retrieved from components::StatisticsStorage.
See utils::statistics::Writer for an information on how to write metrics.
For introduction to metrics see Statistics and Metrics
Definition at line 35 of file storage.hpp.
Public Member Functions | |
| Storage (const Storage &)=delete | |
| Storage & | operator= (const Storage &)=delete |
| void | RegisterWriter (ResourceScopeStorage &scopes, std::string common_prefix, WriterFunc func, std::vector< Label > add_labels={}) |
| Add a writer function func. Note that func is called concurrently with other code, so it should be thread-safe. | |
| void utils::statistics::Storage::RegisterWriter | ( | ResourceScopeStorage & | scopes, |
| std::string | common_prefix, | ||
| WriterFunc | func, | ||
| std::vector< Label > | add_labels = {} ) |
Add a writer function func. Note that func is called concurrently with other code, so it should be thread-safe.
Registration runs after construction via ResourceScopeStorage::AfterConstruction. Unregister runs in ResourceScopeStorage::BeforeDestruction. The storage must outlive its registrations. If other scopes initialize or destroy data accessed by func (generally discouraged), register the statistics scope after them so the data is initialized before the callback is registered and destroyed after it is unregistered.
In a component constructor prefer RegisterWriterScope with components::ComponentContext.
| scopes | storage that owns the writer lifetime. See where to obtain scopes. |
| common_prefix | prefix for the metric, for example "my.metric_name" |
| func | function that writes metrics to utils::statistics::Writer |
| add_labels | common labels for the metric, for example {"database", "dbname"} |