aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/metrics/gauge.h
blob: 55de96cc0a732b2393d302978347985e5ef295ef (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <memory>
#include "metric_id.h"
#include "point.h"

namespace vespalib {
namespace metrics {

class MetricsManager;
struct GaugeAggregator;

/**
 * Represents a gauge metric that can be measured.
 **/
class Gauge {
private:
    std::shared_ptr<MetricsManager> _manager;
    MetricId _id;
public:
    Gauge(std::shared_ptr<MetricsManager> m, MetricId id)
        : _manager(std::move(m)), _id(id)
    {}

    /**
     * Provide a sample for the gauge.
     * @param value the measurement for this sample
     * @param p the point representing labels for this sample (default empty)
     **/
    void sample(double value, Point p = Point::empty) const;

    // internal
    struct Measurement {
        using Key = std::pair<MetricId, Point>;
        Key idx;
        double value;
        Measurement() = delete;
        Measurement(Key k, double v) : idx(k), value(v) {}
    };

    using aggregator_type = GaugeAggregator;
    using sample_type = Measurement;
};

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