]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/prometheus-cpp/core/src/gauge.cc
1 #include "prometheus/gauge.h"
7 Gauge::Gauge(const double value
) : value_
{value
} {}
9 void Gauge::Increment() { Increment(1.0); }
11 void Gauge::Increment(const double value
) { Change(value
); }
13 void Gauge::Decrement() { Decrement(1.0); }
15 void Gauge::Decrement(const double value
) { Change(-1.0 * value
); }
17 void Gauge::Set(const double value
) { value_
.store(value
); }
19 void Gauge::Change(const double value
) {
20 // C++ 20 will add std::atomic::fetch_add support for floating point types
21 auto current
= value_
.load();
22 while (!value_
.compare_exchange_weak(current
, current
+ value
)) {
23 // intentionally empty block
27 void Gauge::SetToCurrentTime() {
28 const auto time
= std::time(nullptr);
29 Set(static_cast<double>(time
));
32 double Gauge::Value() const { return value_
; }
34 ClientMetric
Gauge::Collect() const {
36 metric
.gauge
.value
= Value();
40 } // namespace prometheus