aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/metrics/metrics_manager.h
blob: 7587739ed6a093b2cb66fe79a02ddb9a2af303e9 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <memory>
#include <thread>
#include <vespa/vespalib/stllike/string.h>
#include "counter.h"
#include "gauge.h"
#include "current_samples.h"
#include "snapshots.h"
#include "point.h"
#include "point_builder.h"
#include "dimension.h"
#include "label.h"

namespace vespalib::metrics {

/**
 * Interface for a Metrics manager, for creating metrics
 * and for fetching snapshots.
 **/
class MetricsManager
    : public std::enable_shared_from_this<MetricsManager>
{
public:
    virtual ~MetricsManager() {}

    /**
     * Get or create a counter metric.
     * @param name the name of the metric.
     **/
    virtual Counter counter(const vespalib::string &name, const vespalib::string &description) = 0;

    /**
     * Get or create a gauge metric.
     * @param name the name of the metric.
     **/
    virtual Gauge gauge(const vespalib::string &name, const vespalib::string &description) = 0;

    /**
     * Get or create a dimension for labeling metrics.
     * @param name the name of the dimension.
     **/
    virtual Dimension dimension(const vespalib::string &name) = 0; // get or create

    /**
     * Get or create a label.
     * @param value the label value.
     **/
    virtual Label label(const vespalib::string &value) = 0; // get or create

    /**
     * Create a PointBuilder for labeling metrics.
     **/
    PointBuilder pointBuilder() {
        return PointBuilder(shared_from_this());
    }

    /**
     * Create a PointBuilder for labeling metrics, starting with
     * an Point of already existing dimension/label pairs, which can
     * then be added to or changed.
     * @param from provide a Point to start from.
     *
     **/
    virtual PointBuilder pointBuilder(Point from) = 0;

    /**
     * Create a snapshot of sampled metrics (usually for the last minute).
     **/
    virtual Snapshot snapshot() = 0;

    /**
     * Create a snapshot of all sampled metrics the manager has seen.
     **/
    virtual Snapshot totalSnapshot() = 0;

    // for use from PointBuilder only
    virtual Point pointFrom(PointMap map) = 0;

    // for use from Counter only
    virtual void add(Counter::Increment inc) = 0;

    // for use from Gauge only
    virtual void sample(Gauge::Measurement value) = 0;
};


} // namespace vespalib::metrics