Loading...
Searching...
No Matches
family.h
#pragma once
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#include <vector>
#include "prometheus/client_metric.h"
#include "prometheus/collectable.h"
#include "prometheus/detail/core_export.h"
#include "prometheus/detail/future_std.h"
#include "prometheus/detail/utils.h"
#include "prometheus/labels.h"
#include "prometheus/metric_family.h"
// IWYU pragma: no_include "prometheus/counter.h"
// IWYU pragma: no_include "prometheus/gauge.h"
// IWYU pragma: no_include "prometheus/histogram.h"
// IWYU pragma: no_include "prometheus/summary.h"
namespace prometheus {
template <typename T>
class PROMETHEUS_CPP_CORE_EXPORT Family : public Collectable {
public:
Family(const std::string& name, const std::string& help,
const Labels& constant_labels);
template <typename... Args>
T& Add(const Labels& labels, Args&&... args) {
return Add(labels, detail::make_unique<T>(args...));
}
void Remove(T* metric);
bool Has(const Labels& labels) const;
const std::string& GetName() const;
const Labels GetConstantLabels() const;
std::vector<MetricFamily> Collect() const override;
private:
std::unordered_map<Labels, std::unique_ptr<T>, detail::LabelHasher> metrics_;
const std::string name_;
const std::string help_;
const Labels constant_labels_;
mutable std::mutex mutex_;
ClientMetric CollectMetric(const Labels& labels, T* metric) const;
T& Add(const Labels& labels, std::unique_ptr<T> object);
};
} // namespace prometheus
prometheus::Collectable
Interface implemented by anything that can be used by Prometheus to collect metrics.
Definition collectable.h:17
prometheus::Family
A metric of type T with a set of labeled dimensions.
Definition family.h:61
prometheus::Family::Add
T & Add(const Labels &labels, Args &&... args)
Add a new dimensional data.
Definition family.h:112
prometheus::ClientMetric
Definition client_metric.h:12