userver: userver/utils/statistics/metrics_storage.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
metrics_storage.hpp
1#pragma once
2
3#include <vector>
4
5#include <userver/utils/statistics/fwd.hpp>
6#include <userver/utils/statistics/metric_tag.hpp>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace utils::statistics {
11
12/// @brief Storage of metrics registered with MetricTag<Metric>
13/// @note The class is thread-safe. See also the note about thread-safety
14/// on MetricTag<Metric>.
15class MetricsStorage final {
16 public:
17 MetricsStorage();
18
19 [[nodiscard]] std::vector<Entry> RegisterIn(Storage& statistics_storage);
20
21 /// Get metric data by type
22 template <typename Metric>
23 Metric& GetMetric(const MetricTag<Metric>& tag) {
24 return impl::GetMetric<Metric>(metrics_, tag.key_);
25 }
26
27 void ResetMetrics();
28
29 private:
30 impl::MetricMap metrics_;
31};
32
33using MetricsStoragePtr = std::shared_ptr<MetricsStorage>;
34
35} // namespace utils::statistics
36
37USERVER_NAMESPACE_END