Fine-grained application metrics and reporting.
- Event counters
- Timers w/ distribution estimates & percentiles
- One, five, fifteen minute rates
Usage, TL;DR edition:
ccmetrics::MetricRegistry registry;
void work() {
UPDATE_COUNTER("work", registry);
if (fast_path) {
//
// stuff
//
} else {
SCOPED_TIMER("slow", registry);
//
// expensive stuff
//
}
}
//
// Reporting
//
for (auto& entry : registry.counters()) {
printf("%s %" PRId64"\n", entry.first.c_str(),
entry.second->value());
}
for (auto& entry : registry.timers()) {
printf("%s %" PRId64" %f %f %f\n", entry.first.c_str(),
entry.second->count(),
entry.second->oneMinuteRate(),
entry.second->fiveMinuteRate(),
entry.second->fifteenMinuteRate());
if (g_verbose) {
printf("99th percentile: %f\n", entry.second->snapshot().get99tile());
}
}
Tip of the hat to Coda Hale / Yammer.
ccmetrics is known to work on the following platforms / compilers:
- Windows with Visual Studio 2013+ (dynamic linking only)
- Linux with GCC 4.8
- OS X 10.6+ with Xcode 6.2+
It should build with any compiler that supports C++11 language features like
auto
type specification and std::atomic
support. Platforms without a
pthreads
implementation will likely need to port the TLS implementation in
thread_local_detail.h.
Copyright © 2015 Nathan Rosenblum [email protected]
Licensed under the MIT License.
This library was inspired by the excellent Java metrics library, and owes many of its interfaces to that project.
ccmetrics uses several other open-source libraries:
- RapidJSON for JSON serialization
- cppformat for general formatting
- Google Test for unit tests