3 Copyright (C) 2013-2020 Minetest core developers team
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "util/thread.h"
28 MetricCounter() = default;
30 virtual ~MetricCounter() {}
32 virtual void increment(double number
= 1.0) = 0;
33 virtual double get() const = 0;
36 typedef std::shared_ptr
<MetricCounter
> MetricCounterPtr
;
38 class SimpleMetricCounter
: public MetricCounter
41 SimpleMetricCounter() = delete;
43 virtual ~SimpleMetricCounter() {}
45 SimpleMetricCounter(const std::string
&name
, const std::string
&help_str
) :
46 MetricCounter(), m_name(name
), m_help_str(help_str
),
51 virtual void increment(double number
)
53 MutexAutoLock
lock(m_mutex
);
56 virtual double get() const
58 MutexAutoLock
lock(m_mutex
);
64 std::string m_help_str
;
66 mutable std::mutex m_mutex
;
73 MetricGauge() = default;
74 virtual ~MetricGauge() {}
76 virtual void increment(double number
= 1.0) = 0;
77 virtual void decrement(double number
= 1.0) = 0;
78 virtual void set(double number
) = 0;
79 virtual double get() const = 0;
82 typedef std::shared_ptr
<MetricGauge
> MetricGaugePtr
;
84 class SimpleMetricGauge
: public MetricGauge
87 SimpleMetricGauge() = delete;
89 SimpleMetricGauge(const std::string
&name
, const std::string
&help_str
) :
90 MetricGauge(), m_name(name
), m_help_str(help_str
), m_gauge(0.0)
94 virtual ~SimpleMetricGauge() {}
96 virtual void increment(double number
)
98 MutexAutoLock
lock(m_mutex
);
101 virtual void decrement(double number
)
103 MutexAutoLock
lock(m_mutex
);
106 virtual void set(double number
)
108 MutexAutoLock
lock(m_mutex
);
111 virtual double get() const
113 MutexAutoLock
lock(m_mutex
);
119 std::string m_help_str
;
121 mutable std::mutex m_mutex
;
128 MetricsBackend() = default;
130 virtual ~MetricsBackend() {}
132 virtual MetricCounterPtr
addCounter(
133 const std::string
&name
, const std::string
&help_str
);
134 virtual MetricGaugePtr
addGauge(
135 const std::string
&name
, const std::string
&help_str
);
139 MetricsBackend
*createPrometheusMetricsBackend();