Prometheus Client Library for Modern C++
Loading...
Searching...
No Matches
family.h
1#pragma once
2
3#include <memory>
4#include <mutex>
5#include <string>
6#include <unordered_map>
7#include <vector>
8
9#include "prometheus/client_metric.h"
10#include "prometheus/collectable.h"
11#include "prometheus/detail/core_export.h"
12#include "prometheus/detail/future_std.h"
13#include "prometheus/detail/utils.h"
14#include "prometheus/labels.h"
15#include "prometheus/metric_family.h"
16
17// IWYU pragma: no_include "prometheus/counter.h"
18// IWYU pragma: no_include "prometheus/gauge.h"
19// IWYU pragma: no_include "prometheus/histogram.h"
20// IWYU pragma: no_include "prometheus/summary.h"
21
22namespace prometheus {
23
60template <typename T>
61class PROMETHEUS_CPP_CORE_EXPORT Family : public Collectable {
62 public:
91 Family(const std::string& name, const std::string& help,
92 const Labels& constant_labels);
93
111 template <typename... Args>
112 T& Add(const Labels& labels, Args&&... args) {
113 return Add(labels, detail::make_unique<T>(args...));
114 }
115
120 void Remove(T* metric);
121
125 bool Has(const Labels& labels) const;
126
130 const std::string& GetName() const;
131
135 const Labels GetConstantLabels() const;
136
142 std::vector<MetricFamily> Collect() const override;
143
144 private:
145 std::unordered_map<Labels, std::unique_ptr<T>, detail::LabelHasher> metrics_;
146
147 const std::string name_;
148 const std::string help_;
149 const Labels constant_labels_;
150 mutable std::mutex mutex_;
151
152 ClientMetric CollectMetric(const Labels& labels, T* metric) const;
153 T& Add(const Labels& labels, std::unique_ptr<T> object);
154};
155
156} // namespace prometheus
Interface implemented by anything that can be used by Prometheus to collect metrics.
Definition collectable.h:17
A metric of type T with a set of labeled dimensions.
Definition family.h:61
T & Add(const Labels &labels, Args &&... args)
Add a new dimensional data.
Definition family.h:112
Definition client_metric.h:12