1
1
#pragma once
2
2
3
3
#include < algorithm>
4
+ #include < cassert>
4
5
#include < functional>
5
6
#include < map>
6
7
#include < memory>
15
16
#include " gauge_builder.h"
16
17
#include " histogram_builder.h"
17
18
#include " metric.h"
19
+ #include " metric_family.h"
18
20
19
21
namespace prometheus {
20
22
@@ -32,7 +34,7 @@ class Family : public Collectable {
32
34
void Remove (T* metric);
33
35
34
36
// Collectable
35
- std::vector<io::prometheus::client:: MetricFamily> Collect () override ;
37
+ std::vector<MetricFamily> Collect () override ;
36
38
37
39
private:
38
40
std::unordered_map<std::size_t , std::unique_ptr<T>> metrics_;
@@ -44,7 +46,7 @@ class Family : public Collectable {
44
46
const std::map<std::string, std::string> constant_labels_;
45
47
std::mutex mutex_;
46
48
47
- io::prometheus::client::Metric CollectMetric (std::size_t hash, T* metric);
49
+ ClientMetric CollectMetric (std::size_t hash, T* metric);
48
50
49
51
static std::size_t hash_labels (
50
52
const std::map<std::string, std::string>& labels);
@@ -116,27 +118,27 @@ void Family<T>::Remove(T* metric) {
116
118
}
117
119
118
120
template <typename T>
119
- std::vector<io::prometheus::client:: MetricFamily> Family<T>::Collect() {
121
+ std::vector<MetricFamily> Family<T>::Collect() {
120
122
std::lock_guard<std::mutex> lock{mutex_};
121
- auto family = io::prometheus::client:: MetricFamily{};
122
- family.set_name ( name_) ;
123
- family.set_help ( help_) ;
124
- family.set_type ( T::metric_type) ;
123
+ auto family = MetricFamily{};
124
+ family.name = name_;
125
+ family.help = help_;
126
+ family.type = T::metric_type;
125
127
for (const auto & m : metrics_) {
126
- * family.add_metric () = std::move (CollectMetric (m.first , m.second .get ()));
128
+ family.metric . push_back ( std::move (CollectMetric (m.first , m.second .get () )));
127
129
}
128
130
return {family};
129
131
}
130
132
131
133
template <typename T>
132
- io::prometheus::client::Metric Family<T>::CollectMetric(std::size_t hash,
133
- T* metric) {
134
+ ClientMetric Family<T>::CollectMetric(std::size_t hash, T* metric) {
134
135
auto collected = metric->Collect ();
135
136
auto add_label =
136
137
[&collected](const std::pair<std::string, std::string>& label_pair) {
137
- auto pair = collected.add_label ();
138
- pair->set_name (label_pair.first );
139
- pair->set_value (label_pair.second );
138
+ auto label = ClientMetric::Label{};
139
+ label.name = label_pair.first ;
140
+ label.value = label_pair.second ;
141
+ collected.label .push_back (std::move (label));
140
142
};
141
143
std::for_each (constant_labels_.cbegin (), constant_labels_.cend (), add_label);
142
144
const auto & metric_labels = labels_.at (hash);
0 commit comments