Statistics writers, metric types, and histogram helpers.
Classes | |
| class | BaseFormatBuilder |
| class | BusyMarker |
| A RAII-style guard to account code block execution time in utils::statistics::BusyStorage. Aware of recursive invocations in the same thread. More... | |
| class | BusyStorage |
| class | DuplicateLabelError |
| Thrown when one metric lists the same label name more than once. The values may differ. More... | |
| class | DuplicateMetricError |
| Thrown when a snapshot contains two metrics with the same path and labels. More... | |
| class | Histogram |
| A histogram with a dynamically-allocated array of buckets. More... | |
| class | HistogramAggregator |
| Used to aggregate multiple utils::statistics::Histogram metrics. More... | |
| class | HistogramView |
| The non-owning reader API for "histogram" metrics. More... | |
| class | InvalidMetricError |
| Thrown when metrics written into a snapshot are invalid. More... | |
| class | Label |
| Label name+value storage. More... | |
| class | LabelsSpan |
| View over a continuous range of LabelView. More... | |
| class | LabelView |
| Non owning label name+value storage. More... | |
| class | MetricQueryError |
| Thrown by utils::statistics::Snapshot queries on unexpected metrics states. More... | |
| class | MetricsStorage |
| Storage of metrics registered with MetricTag<Metric>. More... | |
| class | MetricTag |
| Metric description and registration in a declarative way. More... | |
| class | MetricValue |
| The value of a metric. More... | |
| struct | MetricView |
| A non-owning view of a single metric: its path, labels and value. More... | |
| class | MinMaxAvg |
| Class for concurrent safe calculation of minimum, maximum and average over series of values. More... | |
| class | MonotonicByLabelStorage |
| Thread-safe monotonic storage of metrics indexed by label values. More... | |
| class | Percentile |
| Class allows easy calculation of percentiles. More... | |
| struct | Rate |
| Rate metrics (or "counter" metrics) are metrics that only monotonically increase or are reset to zero on restart. Some monitoring systems give them special treatment with regard to maintaining proper non-negative derivative. More... | |
| class | RateCounter |
| Atomic counter of type Rate with relaxed memory ordering by default. More... | |
| class | RecentPeriod |
| Class maintains circular buffer of Counters. More... | |
| class | RelaxedCounter |
| Atomic counter of type T with relaxed memory ordering. More... | |
| class | Request |
| Class describing the request for metrics data. More... | |
| class | Snapshot |
| A snapshot of metrics dumped via utils::statistics::Writer. More... | |
| struct | SnapshotBuildOptions |
| Filters metrics collected by utils::statistics::Snapshot constructors. More... | |
| struct | SnapshotLoadOptions |
| Prefix and labels applied to every metric in utils::statistics::Snapshot::FromJson and utils::statistics::Snapshot::FromLayeredJson. More... | |
| class | Storage |
| class | StripedRateCounter |
| Atomic counter of type Rate with relaxed memory ordering, increased memory consumption and decreased contention. More... | |
| struct | Warning |
| class | Writer |
| Class for writing metrics that is provided by utils::statistics::Storage. More... | |
Typedefs | |
| using | MetricsStoragePtr = std::shared_ptr<MetricsStorage> |
| using | PortabilityWarnings = std::unordered_map<WarningCode, std::vector<Warning>> |
| using | WriterFuncRef = utils::function_ref<void(Writer&) const> |
| Non-owning reference to a function that writes metrics via utils::statistics::Writer. | |
| using | WriterFunc = std::function<void(Writer&)> |
Functions | |
| std::string | DurationToString (std::chrono::seconds duration) |
| std::string | ToGraphiteFormat (WriterFuncRef writer, const Request &statistics_request={}) |
| Output statistics in Graphite format with tags (labels). | |
| std::string | ToGraphiteFormat (const HasWriterSupport auto &metric, const Request &statistics_request={}) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| void | DumpMetric (Writer &writer, const Histogram &histogram) |
| Metric serialization support for Histogram. | |
| void | DumpMetric (Writer &writer, const HistogramAggregator &histogram) |
| Metric serialization support for utils::statistics::HistogramAggregator. | |
| bool | operator== (HistogramView lhs, HistogramView rhs) noexcept |
| std::string | ToJsonFormat (WriterFuncRef writer, const Request &statistics_request={}) |
| std::string | ToJsonFormat (const HasWriterSupport auto &metric, const Request &statistics_request={}) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| std::strong_ordering | operator<=> (const LabelView &x, const LabelView &y) noexcept |
| bool | operator== (const LabelView &x, const LabelView &y) noexcept |
| std::strong_ordering | operator<=> (const Label &x, const Label &y) noexcept |
| bool | operator== (const Label &x, const Label &y) noexcept |
| template<typename ValueType, typename AverageType> | |
| auto | Serialize (const MinMaxAvg< ValueType, AverageType > &mma, formats::serialize::To< formats::json::Value >) |
| template<typename ValueType, typename AverageType> | |
| void | DumpMetric (Writer &writer, const MinMaxAvg< ValueType, AverageType > &value) |
| std::string | GetPercentileFieldName (double perc) |
| template<size_t M, typename Counter, size_t ExtraBuckets, size_t ExtraBucketSize> | |
| void | DumpMetric (Writer &writer, const Percentile< M, Counter, ExtraBuckets, ExtraBucketSize > &perc, std::initializer_list< double > percents={0, 50, 90, 95, 98, 99, 99.6, 99.9, 100}) |
| formats::json::Value | Serialize (const std::vector< Label > &labels, formats::serialize::To< formats::json::Value >) |
| formats::json::Value | Serialize (const Warning &entry, formats::serialize::To< formats::json::Value >) |
| std::string_view | ToString (WarningCode code) |
| formats::json::Value | Serialize (const PortabilityWarnings &info, formats::serialize::To< formats::json::Value >) |
| PortabilityWarnings | GetPortabilityWarnings (WriterFuncRef writer, const Request &request) |
| PortabilityWarnings | GetPortabilityWarnings (const HasWriterSupport auto &metric, const Request &request) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| std::string | ToPrettyFormat (WriterFuncRef writer, const Request &statistics_request={}) |
| Output statistics in a human-readable, compact format, useful for visual inspection. | |
| std::string | ToPrettyFormat (const HasWriterSupport auto &metric, const Request &statistics_request={}) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| std::string | ToPrometheusFormat (WriterFuncRef writer, const Request &request={}) |
| Output statistics in Prometheus format, each metric has gauge type. | |
| std::string | ToPrometheusFormat (const HasWriterSupport auto &metric, const Request &request={}) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| std::string | ToPrometheusFormatUntyped (WriterFuncRef writer, const Request &request={}) |
| Output statistics in Prometheus format, without metric types. | |
| std::string | ToPrometheusFormatUntyped (const HasWriterSupport auto &metric, const Request &request={}) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| Rate | operator+ (Rate first, Rate second) noexcept |
| void | DumpMetric (Writer &writer, const RateCounter &value) |
| void | ResetMetric (RateCounter &value) |
| template<typename Counter, typename Result, typename Timer> | |
| void | DumpMetric (Writer &writer, const RecentPeriod< Counter, Result, Timer > &recent_period) |
| Exports the full configured window of utils::statistics::RecentPeriod, excluding the current epoch. Use utils::statistics::RecentPeriod::GetStatsForPeriod explicitly when a different window or inclusion of the current epoch is required. | |
| template<typename Counter, typename Result, typename Timer> | |
| void | ResetMetric (RecentPeriod< Counter, Result, Timer > &recent_period) |
| Reset support for RecentPeriod. | |
| template<typename T> | |
| void | DumpMetric (Writer &writer, const RelaxedCounter< T > &value) |
| template<typename T> | |
| void | ResetMetric (RelaxedCounter< T > &value) |
| std::string | ToSolomonFormat (WriterFuncRef writer, const std::unordered_map< std::string, std::string > &common_labels, const Request &statistics_request={}) |
| std::string | ToSolomonFormat (const HasWriterSupport auto &metric, const std::unordered_map< std::string, std::string > &common_labels, const Request &statistics_request={}) |
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
| void | VisitMetrics (WriterFuncRef func, BaseFormatBuilder &out, const Request &request={}) |
| Low-level connecting function that dumps metrics from func into out. | |
| void | VisitMetrics (const HasWriterSupport auto &metric, BaseFormatBuilder &out, const Request &request={}) |
| template<class Metric> | |
| void | DumpMetric (Writer &writer, const std::atomic< Metric > &m) |
| void | DumpMetric (Writer &writer, const MetricView &metric) |
| Writes metric through writer. | |
| void | PrintTo (const Snapshot &data, std::ostream *) |
| Support for gtest diagnostics for utils::statistics::Snapshot. | |
| void | PrintTo (MetricValue value, std::ostream *) |
| Support for gtest diagnostics for utils::statistics::MetricValue. | |
| void | PrintTo (Rate value, std::ostream *) |
| Support for gtest diagnostics for utils::statistics::Rate. | |
| ::testing::Matcher< Snapshot > | EqualsNumerically (const Snapshot &expected) |
| GTest matcher for utils::statistics::Snapshot::EqualsNumerically. | |
| void | RegisterWriterScope (const components::ComponentContext &, std::string common_prefix, WriterFunc func, std::vector< Label > add_labels={}) |
| Registers a writer in the default components::StatisticsStorage. Call this helper in the component constructor. Registration is deferred until the complete component, including derived classes, has been constructed. The callback is unregistered before the component destructor starts. The callback may run concurrently with other code and must be thread-safe. | |
| MetricsStoragePtr | MakeBoundMetricsStorage (Storage &storage, const std::optional< std::vector< std::string > > &allowed_metric_paths) |
| Creates a MetricsStorage that considers only MetricTag<Metric> instances whose paths are listed in allowed_metric_paths (or all of them, if it is std::nullopt), and registers it in storage using the scoped utils::statistics::Storage::RegisterWriter overload, with an empty prefix. | |
| void | DumpMetric (Writer &writer, const Storage &storage) |
| Dumps metrics registered in storage. | |
| void | DumpMetric (Writer &writer, const StripedRateCounter &value) |
| void | ResetMetric (StripedRateCounter &value) |
Variables | |
| constexpr auto | kDefaultMaxPeriod = std::chrono::seconds(60) |
| constexpr auto | kDefaultEpochDuration = std::chrono::seconds(5) |
| typedef std::shared_ptr< MetricsStorage > utils::statistics::MetricsStoragePtr = std::shared_ptr<MetricsStorage> |
| using utils::statistics::PortabilityWarnings = std::unordered_map<WarningCode, std::vector<Warning>> |
Definition at line 54 of file portability_info.hpp.
| using utils::statistics::WriterFunc = std::function<void(Writer&)> |
Definition at line 20 of file storage.hpp.
| typedef utils::function_ref< void(Writer &) const > utils::statistics::WriterFuncRef = utils::function_ref<void(Writer&) const> |
Non-owning reference to a function that writes metrics via utils::statistics::Writer.
|
strong |
Definition at line 31 of file portability_info.hpp.
| void utils::statistics::DumpMetric | ( | Writer & | writer, |
| const MinMaxAvg< ValueType, AverageType > & | value ) |
Definition at line 152 of file min_max_avg.hpp.
| void utils::statistics::DumpMetric | ( | Writer & | writer, |
| const Percentile< M, Counter, ExtraBuckets, ExtraBucketSize > & | perc, | ||
| std::initializer_list< double > | percents = {0, 50, 90, 95, 98, 99, 99.6, 99.9, 100} ) |
Definition at line 217 of file percentile.hpp.
| void utils::statistics::DumpMetric | ( | Writer & | writer, |
| const RecentPeriod< Counter, Result, Timer > & | recent_period ) |
Exports the full configured window of utils::statistics::RecentPeriod, excluding the current epoch. Use utils::statistics::RecentPeriod::GetStatsForPeriod explicitly when a different window or inclusion of the current epoch is required.
Definition at line 191 of file recentperiod.hpp.
| void utils::statistics::DumpMetric | ( | Writer & | writer, |
| const RelaxedCounter< T > & | value ) |
Definition at line 79 of file relaxed_counter.hpp.
| void utils::statistics::DumpMetric | ( | Writer & | writer, |
| const std::atomic< Metric > & | m ) |
Definition at line 226 of file writer.hpp.
GTest matcher for utils::statistics::Snapshot::EqualsNumerically.
| PortabilityWarnings utils::statistics::GetPortabilityWarnings | ( | const HasWriterSupport auto & | metric, |
| const Request & | request ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 86 of file portability_info.hpp.
| PortabilityWarnings utils::statistics::GetPortabilityWarnings | ( | WriterFuncRef | writer, |
| const Request & | request ) |
Output portability info for statistics.
| MetricsStoragePtr utils::statistics::MakeBoundMetricsStorage | ( | Storage & | storage, |
| const std::optional< std::vector< std::string > > & | allowed_metric_paths ) |
Creates a MetricsStorage that considers only MetricTag<Metric> instances whose paths are listed in allowed_metric_paths (or all of them, if it is std::nullopt), and registers it in storage using the scoped utils::statistics::Storage::RegisterWriter overload, with an empty prefix.
The returned pointer is an aliasing shared_ptr: it keeps alive an internal holder that unregisters the writer when the last pointer is destroyed. The storage must outlive the returned pointer (and all its copies).
|
noexcept |
Compares equal if bounds are close and values are equal. Bucket sums are ignored.
| void utils::statistics::PrintTo | ( | const Snapshot & | data, |
| std::ostream * | ) |
Support for gtest diagnostics for utils::statistics::Snapshot.
Valid usage:
Invalid usage:
| void utils::statistics::RegisterWriterScope | ( | const components::ComponentContext & | , |
| std::string | common_prefix, | ||
| WriterFunc | func, | ||
| std::vector< Label > | add_labels = {} ) |
Registers a writer in the default components::StatisticsStorage. Call this helper in the component constructor. Registration is deferred until the complete component, including derived classes, has been constructed. The callback is unregistered before the component destructor starts. The callback may run concurrently with other code and must be thread-safe.
Uses components::ComponentContext::Scopes for the component automatically. See choosing scopes for the lifetime rules.
| void utils::statistics::ResetMetric | ( | RecentPeriod< Counter, Result, Timer > & | recent_period | ) |
Reset support for RecentPeriod.
Definition at line 197 of file recentperiod.hpp.
| void utils::statistics::ResetMetric | ( | RelaxedCounter< T > & | value | ) |
Definition at line 84 of file relaxed_counter.hpp.
| auto utils::statistics::Serialize | ( | const MinMaxAvg< ValueType, AverageType > & | mma, |
| formats::serialize::To< formats::json::Value > | ) |
Definition at line 146 of file min_max_avg.hpp.
| formats::json::Value utils::statistics::Serialize | ( | const PortabilityWarnings & | info, |
| formats::serialize::To< formats::json::Value > | ) |
JSON serialization for the PortabilityInfo in the following format:
| std::string utils::statistics::ToGraphiteFormat | ( | const HasWriterSupport auto & | metric, |
| const Request & | statistics_request = {} ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 20 of file graphite.hpp.
| std::string utils::statistics::ToJsonFormat | ( | const HasWriterSupport auto & | metric, |
| const Request & | statistics_request = {} ) |
| std::string utils::statistics::ToJsonFormat | ( | WriterFuncRef | writer, |
| const Request & | statistics_request = {} ) |
Output statistics in JSON format:
| std::string utils::statistics::ToPrettyFormat | ( | const HasWriterSupport auto & | metric, |
| const Request & | statistics_request = {} ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 29 of file pretty_format.hpp.
| std::string utils::statistics::ToPrettyFormat | ( | WriterFuncRef | writer, |
| const Request & | statistics_request = {} ) |
Output statistics in a human-readable, compact format, useful for visual inspection.
The current version of this unstable format is:
| std::string utils::statistics::ToPrometheusFormat | ( | const HasWriterSupport auto & | metric, |
| const Request & | request = {} ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 36 of file prometheus.hpp.
| std::string utils::statistics::ToPrometheusFormatUntyped | ( | const HasWriterSupport auto & | metric, |
| const Request & | request = {} ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 44 of file prometheus.hpp.
| std::string utils::statistics::ToSolomonFormat | ( | const HasWriterSupport auto & | metric, |
| const std::unordered_map< std::string, std::string > & | common_labels, | ||
| const Request & | statistics_request = {} ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 69 of file solomon.hpp.
| std::string utils::statistics::ToSolomonFormat | ( | WriterFuncRef | writer, |
| const std::unordered_map< std::string, std::string > & | common_labels, | ||
| const Request & | statistics_request = {} ) |
Output statistics in Solomon format with tags (labels). It's JSON format in the form
| void utils::statistics::VisitMetrics | ( | const HasWriterSupport auto & | metric, |
| BaseFormatBuilder & | out, | ||
| const Request & | request = {} ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Dumps metric via writer = metric (DumpMetric / built-in Writer support).
| void utils::statistics::VisitMetrics | ( | WriterFuncRef | func, |
| BaseFormatBuilder & | out, | ||
| const Request & | request = {} ) |
Low-level connecting function that dumps metrics from func into out.
Calls func with a utils::statistics::Writer. Each metric written through that Writer is forwarded to out.HandleMetric. request filters the metrics and may attach extra labels; request.prefix is a match filter, not a path to write under.
This function dumps Writer-based metrics. It is used to implement formats such as:
To define a custom output format, implement utils::statistics::BaseFormatBuilder:
Collect metrics using the custom format builder:
| func | writes metrics to the provided utils::statistics::Writer |
| out | receives each written metric via utils::statistics::BaseFormatBuilder::HandleMetric |
| request | metric filter and extra labels |
|
constexpr |
Definition at line 17 of file common.hpp.
|
constexpr |
Definition at line 15 of file common.hpp.