Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
MetricBase.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2023, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "util/prometheus/OStream.hpp"
23
24#include <string>
25
26namespace util::prometheus {
27
32public:
39 MetricBase(std::string name, std::string labelsString);
40
41 MetricBase(MetricBase const&) = delete;
42 MetricBase(MetricBase&&) = default;
44 operator=(MetricBase const&) = delete;
46 operator=(MetricBase&&) = default;
47 virtual ~MetricBase() = default;
48
55 friend OStream&
56 operator<<(OStream& stream, MetricBase const& metricBase);
57
62 std::string const&
63 name() const;
64
69 std::string const&
70 labelsString() const;
71
72protected:
78 virtual void
79 serializeValue(OStream& stream) const = 0;
80
81private:
82 std::string name_;
83 std::string labelsString_;
84};
85
86enum class MetricType { CounterInt, CounterDouble, GaugeInt, GaugeDouble, HistogramInt, HistogramDouble, Summary };
87
88char const*
89toString(MetricType type);
90
91} // namespace util::prometheus
A Prometheus histogram metric with a generic value type.
Definition Histogram.hpp:42
Base class for a Prometheus metric containing a name and labels.
Definition MetricBase.hpp:31
friend OStream & operator<<(OStream &stream, MetricBase const &metricBase)
Serialize the metric to a string in Prometheus format.
Definition MetricBase.cpp:36
MetricBase(std::string name, std::string labelsString)
Construct a new MetricBase object.
Definition MetricBase.cpp:30
std::string const & name() const
Get the name of the metric.
Definition MetricBase.cpp:67
virtual void serializeValue(OStream &stream) const =0
Interface to serialize the value of the metric.
std::string const & labelsString() const
Get the labels of the metric in serialized format, e.g. {name="value",name2="value2"}...
Definition MetricBase.cpp:73
A stream that can optionally compress its data.
Definition OStream.hpp:31
std::string toString(ripple::LedgerHeader const &info)
A helper function that converts a ripple::LedgerHeader to a string representation.
Definition LedgerUtils.hpp:215
A prometheus counter metric implementation. It can only be increased or be reset to zero.
Definition Counter.hpp:40
A prometheus gauge metric implementation. It can be increased, decreased or set to a value.
Definition Gauge.hpp:39