aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/metrics/gauge_aggregator.cpp
blob: a6c4559931f45df619afabdfd33c3e6a2c06ac9c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "gauge_aggregator.h"
#include <assert.h>
#include <map>

namespace vespalib {
namespace metrics {

GaugeAggregator::GaugeAggregator(const Gauge::Measurement &sample)
    : idx(sample.idx),
      observedCount(1),
      sumValue(sample.value),
      minValue(sample.value),
      maxValue(sample.value),
      lastValue(sample.value)
{}

void
GaugeAggregator::merge(const GaugeAggregator &other)
{
    assert(idx == other.idx);
    minValue = std::min(minValue, other.minValue);
    maxValue = std::max(maxValue, other.maxValue);
    sumValue += other.sumValue;
    lastValue = other.lastValue;
    observedCount += other.observedCount;
}

} // namespace vespalib::metrics
} // namespace vespalib