20 #include "prometheus/counter.h" 21 #include "prometheus/family.h" 22 #include "prometheus/gauge.h" 23 #include "prometheus/histogram.h" 28 namespace prometheus {
35 explicit Counter(::prometheus::Counter* prometheus)
38 void Increment()
override {
prometheus_->Increment(); }
39 void Increment(
double by_value)
override {
prometheus_->Increment(by_value); }
48 explicit CounterFamily(
49 ::prometheus::Family<::prometheus::Counter>* prometheus)
52 Counter* Add(
const std::map<std::string, std::string>& labels)
override {
53 ::prometheus::Counter* counter = &
prometheus_->Add(labels);
54 auto wrapper = common::make_unique<Counter>(counter);
55 auto* ptr = wrapper.get();
56 wrappers_.emplace_back(std::move(wrapper));
61 ::prometheus::Family<::prometheus::Counter>*
prometheus_;
67 explicit Gauge(::prometheus::Gauge* prometheus) :
prometheus_(prometheus) {}
69 void Decrement()
override {
prometheus_->Decrement(); }
70 void Decrement(
double by_value)
override {
prometheus_->Decrement(by_value); }
71 void Increment()
override {
prometheus_->Increment(); }
72 void Increment(
double by_value)
override {
prometheus_->Increment(by_value); }
73 void Set(
double value)
override {
prometheus_->Set(value); }
82 explicit GaugeFamily(::prometheus::Family<::prometheus::Gauge>* prometheus)
85 Gauge* Add(
const std::map<std::string, std::string>& labels)
override {
86 ::prometheus::Gauge* gauge = &
prometheus_->Add(labels);
87 auto wrapper = common::make_unique<Gauge>(gauge);
88 auto* ptr = wrapper.get();
89 wrappers_.emplace_back(std::move(wrapper));
94 ::prometheus::Family<::prometheus::Gauge>*
prometheus_;
95 std::vector<std::unique_ptr<Gauge>>
wrappers_;
100 explicit Histogram(::prometheus::Histogram* prometheus)
103 void Observe(
double value)
override {
prometheus_->Observe(value); }
110 ::cartographer::metrics::Histogram> {
112 HistogramFamily(::prometheus::Family<::prometheus::Histogram>* prometheus,
113 const BucketBoundaries& boundaries)
116 Histogram* Add(
const std::map<std::string, std::string>& labels)
override {
118 auto wrapper = common::make_unique<Histogram>(histogram);
119 auto* ptr = wrapper.get();
120 wrappers_.emplace_back(std::move(wrapper));
125 ::prometheus::Family<::prometheus::Histogram>*
prometheus_;
126 std::vector<std::unique_ptr<Histogram>>
wrappers_;
133 : registry_(std::make_shared<::prometheus::Registry>()) {}
137 const std::string& description) {
138 auto& family = ::prometheus::BuildCounter()
142 auto wrapper = common::make_unique<CounterFamily>(&family);
143 auto* ptr = wrapper.get();
144 counters_.emplace_back(std::move(wrapper));
150 const std::string& description) {
151 auto& family = ::prometheus::BuildGauge()
155 auto wrapper = common::make_unique<GaugeFamily>(&family);
156 auto* ptr = wrapper.get();
157 gauges_.emplace_back(std::move(wrapper));
163 const std::string& description,
164 const BucketBoundaries& boundaries) {
165 auto& family = ::prometheus::BuildHistogram()
169 auto wrapper = common::make_unique<HistogramFamily>(&family, boundaries);
170 auto* ptr = wrapper.get();
std::weak_ptr<::prometheus::Collectable > GetCollectable() const
::cartographer::metrics::Family<::cartographer::metrics::Gauge > * NewGaugeFamily(const std::string &name, const std::string &description) override
const BucketBoundaries boundaries_
std::vector< std::unique_ptr< ::cartographer::metrics::Family<::cartographer::metrics::Counter > > > counters_
std::vector< double > BucketBoundaries
::cartographer::metrics::Family<::cartographer::metrics::Histogram > * NewHistogramFamily(const std::string &name, const std::string &description, const ::cartographer::metrics::Histogram::BucketBoundaries &boundaries) override
std::vector< std::unique_ptr< ::cartographer::metrics::Family<::cartographer::metrics::Histogram > > > histograms_
::cartographer::metrics::Family<::cartographer::metrics::Counter > * NewCounterFamily(const std::string &name, const std::string &description) override
std::vector< std::unique_ptr< ::cartographer::metrics::Family<::cartographer::metrics::Gauge > > > gauges_
std::shared_ptr<::prometheus::Registry > registry_
::prometheus::Counter * prometheus_
std::vector< std::unique_ptr< Counter > > wrappers_