prom 0.1.0
Client-independent C++23 Prometheus/OpenMetrics metric abstraction
Loading...
Searching...
No Matches
adapter.hpp
Go to the documentation of this file.
1#pragma once
2
17
18#include <prom/adapter.hpp>
19
20#include <memory>
21#include <span>
22#include <string_view>
23
24namespace prometheus {
25class Registry;
26}
27
29
39class PrometheusCppAdapter final : public prom::Adapter {
40public:
43
46 explicit PrometheusCppAdapter(std::shared_ptr<prometheus::Registry> registry);
47
49
52 [[nodiscard]] prometheus::Registry& registry() const noexcept;
53
55 [[nodiscard]] std::shared_ptr<prometheus::Registry> registry_ptr() const noexcept;
56
57 [[nodiscard]] std::string_view backend_name() const noexcept override;
58
59 [[nodiscard]] prom::MetricHandle
60 register_metric(const prom::MetricMeta& meta) noexcept override;
61 [[nodiscard]] prom::MetricHandle resolve(const prom::MetricHandle& family,
62 const prom::Labels& dynamic) noexcept override;
63
64 void inc(const prom::MetricHandle& handle, double amount) noexcept override;
65 void dec(const prom::MetricHandle& handle, double amount) noexcept override;
66 void set(const prom::MetricHandle& handle, double value) noexcept override;
67 void observe(const prom::MetricHandle& handle, double value) noexcept override;
68 void set_info(const prom::MetricHandle& handle,
69 std::span<const prom::Label> labels) noexcept override;
70 void set_state(const prom::MetricHandle& handle,
71 std::string_view state,
72 bool active) noexcept override;
73
74private:
75 class Impl;
76 std::unique_ptr<Impl> impl_;
77};
78
79} // namespace prom::prometheus_cpp
The pluggable backend.
Definition adapter.hpp:62
An immutable-by-convention set of labels, kept sorted by name with duplicates collapsed last-wins.
Definition labels.hpp:55
Creates registered metrics against a single adapter cell.
Definition registry.hpp:112
Maps prom's metric types onto prometheus-cpp families and series.
Definition adapter.hpp:39
void set_state(const prom::MetricHandle &handle, std::string_view state, bool active) noexcept override
Set the boolean value of one member of a state set.
Definition adapter.cpp:266
prom::MetricHandle register_metric(const prom::MetricMeta &meta) noexcept override
Register a metric family.
Definition adapter.cpp:103
prom::MetricHandle resolve(const prom::MetricHandle &family, const prom::Labels &dynamic) noexcept override
Resolve the labeled child of family for the given dynamic labels, creating it on first request.
Definition adapter.cpp:166
void dec(const prom::MetricHandle &handle, double amount) noexcept override
Decrease the series behind handle by amount (gauge).
Definition adapter.cpp:221
prometheus::Registry & registry() const noexcept
The registry backing this adapter — hand it to a prometheus::Exposer or serialize it for a scrape res...
Definition adapter.cpp:91
PrometheusCppAdapter()
Construct with a freshly-allocated, owned registry.
Definition adapter.cpp:83
PrometheusCppAdapter(std::shared_ptr< prometheus::Registry > registry)
Construct around an externally-owned registry (shared), e.g.
void set(const prom::MetricHandle &handle, double value) noexcept override
Set the series behind handle to value (gauge/untyped).
Definition adapter.cpp:228
std::shared_ptr< prometheus::Registry > registry_ptr() const noexcept
Shared ownership of the backing registry.
Definition adapter.cpp:95
std::string_view backend_name() const noexcept override
Stable identifier of the backend (e.g. "null", "prometheus-cpp").
Definition adapter.cpp:99
void set_info(const prom::MetricHandle &handle, std::span< const prom::Label > labels) noexcept override
Replace the label set carried by an info metric.
Definition adapter.cpp:247
void inc(const prom::MetricHandle &handle, double amount) noexcept override
Increase the series behind handle by amount (counter/gauge).
Definition adapter.cpp:209
void observe(const prom::MetricHandle &handle, double value) noexcept override
Record an observation against handle (histogram/summary).
Definition adapter.cpp:235
The backend boundary: MetricMeta, MetricState/MetricHandle, and the pure-virtual Adapter interface.
Definition adapter.hpp:28
Definition adapter.hpp:24
std::shared_ptr< MetricState > MetricHandle
Opaque, backend-owned handle to a registered metric family or a labeled child series.
Definition fwd.hpp:34
Definition adapter.hpp:24
A single name="value" label pair.
Definition labels.hpp:20
The complete, backend-agnostic description of a metric family handed to Adapter::register_metric.
Definition adapter.hpp:31