#include <userver/utils/statistics/writer.hpp>
Class for writing metrics that is provided by utils::statistics::Storage.
Usage is quite straightforward:
The above sample would produce the following metrics:
The Writer can be customized for writing custom metric types by providing a void DumpMetric(utils::statistics::Writer& writer, const CustomMetric& value)
function:
DumpMetric functions nest well, labels are propagated to the nested DumpMetric:
To use the above writers register the metric writer in utils::statistics::Storage component:
The above metrics in Graphite format would look like:
The Writer is usable by the utils::statistics::MetricTag. For example, for the following structure:
The DumpMetric function may look like:
For information on metrics testing in testsuite refer to Testsuite - Metrics.
For metrics testing in unit-tests see utils::statistics::Snapshot.
Definition at line 92 of file writer.hpp.
Public Member Functions | |
Writer (Writer &&other)=delete | |
Writer (const Writer &)=delete | |
Writer & | operator= (Writer &&)=delete |
Writer & | operator= (const Writer &)=delete |
Writer | operator[] (std::string_view path) & |
Returns a Writer with a ('.' + path) appended. | |
Writer | operator[] (std::string_view path) && |
Returns a Writer with a ('.' + path) appended. | |
template<class T > | |
void | operator= (const T &value) |
template<class T > | |
void | ValueWithLabels (const T &value, LabelsSpan labels) |
Write metric value with labels to metrics builder. | |
template<class T > | |
void | ValueWithLabels (const T &value, std::initializer_list< LabelView > il) |
Write metric value with labels to metrics builder. | |
template<class T > | |
void | ValueWithLabels (const T &value, const LabelView &label) |
Write metric value with label to metrics builder. | |
operator bool () const noexcept | |
Static Public Attributes | |
static constexpr char | kDelimiter = '.' |
Path parts delimiter. In other words, writer["a"]["b"] becomes "a.b". | |
|
inlineexplicitnoexcept |
Returns true if this writer would actually write data. Returns false if the data is not required by request and metrics construction could be skipped.
Definition at line 174 of file writer.hpp.
Write metric value to metrics builder via using DumpMetric function.
Definition at line 114 of file writer.hpp.
|
inline |
Write metric value with label to metrics builder.
Definition at line 146 of file writer.hpp.
|
inline |
Write metric value with labels to metrics builder.
Definition at line 132 of file writer.hpp.
|
inline |
Write metric value with labels to metrics builder.
Definition at line 140 of file writer.hpp.
Path parts delimiter. In other words, writer["a"]["b"] becomes "a.b".
Definition at line 95 of file writer.hpp.