Class for writing metrics.
The Writer could be customized by providing a void DumpMetric(utils::statistics::Writer& writer, const Metric& value)
function:
std::atomic<int> nested1{17};
std::atomic<int> nested2{18};
};
writer[
"nested1"] =
m.nested1;
}
DumpMetric functions nest well, labels are propagated to the nested DumpMetric:
};
for (
const auto& [key, value] :
m.metrics) {
}
}
To use the above writers register the metric writer in utils::statistics::Storage component:
writer["metric1"] = 42;
writer["more_metrics"] = metrics;
},
{{"label_for_all", "labell value"}});
The above metrics in Graphite format would look like:
The Writer is usable by the utils::statistics::MetricTag. For example, for the following structure:
struct Stats {
std::atomic<std::uint64_t> opened_sockets{0};
std::atomic<std::uint64_t> closed_sockets{0};
std::atomic<std::uint64_t> bytes_read{0};
};
The DumpMetric function may look like:
writer["sockets"]["opened"] = stats.opened_sockets;
writer["sockets"]["closed"] = stats.closed_sockets;
writer["bytes"]["read"] = stats.bytes_read;
}
void ResetMetric(Stats& stats) {
stats.opened_sockets = 0;
stats.closed_sockets = 0;
stats.bytes_read = 0;
}
For information on metrics testing in testsuite refer to Testsuite - Metrics.
For metrics testing in unit-tests see utils::statistics::Snapshot.
- Examples
- samples/tcp_full_duplex_service/tcp_full_duplex_service.cpp.
Definition at line 83 of file writer.hpp.