Commit 515c1459 authored by Dominik Charousset's avatar Dominik Charousset

Use counters for histograms

parent 32c4f24d
......@@ -24,6 +24,7 @@
#include "caf/config.hpp"
#include "caf/fwd.hpp"
#include "caf/span.hpp"
#include "caf/telemetry/counter.hpp"
#include "caf/telemetry/gauge.hpp"
#include "caf/telemetry/metric_type.hpp"
......@@ -39,11 +40,13 @@ public:
using gauge_type = gauge<value_type>;
using counter_type = counter<value_type>;
using family_setting = std::vector<value_type>;
struct bucket_type {
value_type upper_bound;
gauge_type gauge;
counter_type count;
};
// -- constants --------------------------------------------------------------
......@@ -85,11 +88,11 @@ public:
void observe(value_type value) {
// The last bucket has an upper bound of +inf or int_max, so we'll always
// find a bucket and increment the gauges.
// find a bucket and increment the counters.
for (size_t index = 0;; ++index) {
auto& [upper_bound, gauge] = buckets_[index];
auto& [upper_bound, count] = buckets_[index];
if (value <= upper_bound) {
gauge.inc();
count.inc();
sum_.inc(value);
return;
}
......
......@@ -50,7 +50,7 @@ actor_registry::~actor_registry() {
actor_registry::actor_registry(actor_system& sys) : system_(sys) {
running_ = sys.telemetry().gauge_singleton(
"caf", "running_actors", "Number of currently running actors.");
"caf", "running-actors", "Number of currently running actors.");
}
strong_actor_ptr actor_registry::get_impl(actor_id key) const {
......
......@@ -290,10 +290,10 @@ void prometheus::append_histogram(const metric_family* family,
auto buckets = val->buckets();
size_t index = 0;
for (; index < buckets.size() - 1; ++index) {
append(buf_, vm[index], buckets[index].gauge.value(), ' ',
append(buf_, vm[index], buckets[index].count.value(), ' ',
ms_timestamp{now_}, '\n');
}
auto count = buckets[index].gauge.value();
auto count = buckets[index].count.value();
append(buf_, vm[index], count, ' ', ms_timestamp{now_}, '\n');
append(buf_, vm[++index], val->sum(), ' ', ms_timestamp{now_}, '\n');
append(buf_, vm[++index], count, ' ', ms_timestamp{now_}, '\n');
......
......@@ -53,9 +53,9 @@ CAF_TEST(histograms aggregate to buckets and keep a sum) {
h1.observe(value);
auto buckets = h1.buckets();
CAF_REQUIRE_EQUAL(buckets.size(), 4u);
CAF_CHECK_EQUAL(buckets[0].gauge.value(), 2); // 1, 2
CAF_CHECK_EQUAL(buckets[1].gauge.value(), 2); // 3, 4
CAF_CHECK_EQUAL(buckets[2].gauge.value(), 4); // 5, 6, 7, 8
CAF_CHECK_EQUAL(buckets[3].gauge.value(), 2); // 9, 10
CAF_CHECK_EQUAL(buckets[0].count.value(), 2); // 1, 2
CAF_CHECK_EQUAL(buckets[1].count.value(), 2); // 3, 4
CAF_CHECK_EQUAL(buckets[2].count.value(), 4); // 5, 6, 7, 8
CAF_CHECK_EQUAL(buckets[3].count.value(), 2); // 9, 10
CAF_CHECK_EQUAL(h1.sum(), 55);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment