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/info.h"
21// IWYU pragma: no_include "prometheus/summary.h"
22
23namespace prometheus {
24
61template <typename T>
62class PROMETHEUS_CPP_CORE_EXPORT Family : public Collectable {
63 public:
92 Family(const std::string& name, const std::string& help,
93 const Labels& constant_labels);
94
112 template <typename... Args>
113 T& Add(const Labels& labels, Args&&... args) {
114 return Add(labels, detail::make_unique<T>(args...));
115 }
116
121 void Remove(T* metric);
122
126 bool Has(const Labels& labels) const;
127
131 const std::string& GetName() const;
132
136 const Labels& GetConstantLabels() const;
137
143 std::vector<MetricFamily> Collect() const override;
144
145 private:
146 std::unordered_map<Labels, std::unique_ptr<T>, detail::LabelHasher> metrics_;
147
148 const std::string name_;
149 const std::string help_;
150 const Labels constant_labels_;
151 mutable std::mutex mutex_;
152
153 ClientMetric CollectMetric(const Labels& labels, T* metric) const;
154 T& Add(const Labels& labels, std::unique_ptr<T> object);
155};
156
157} // 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:62
T & Add(const Labels &labels, Args &&... args)
Add a new dimensional data.
Definition family.h:113
Definition client_metric.h:12