prom 0.1.0
Client-independent C++23 Prometheus/OpenMetrics metric abstraction
Loading...
Searching...
No Matches
info.hpp
Go to the documentation of this file.
1#pragma once
2
5
7
8#include <initializer_list>
9#include <string_view>
10#include <utility>
11#include <vector>
12
13namespace prom {
14
16struct InfoSpec {
17 std::string_view name{};
18 std::string_view help{};
20 comms::DisplayInfo display{};
21};
22
25class Info : public MetricBase<Info> {
26public:
27 Info(const std::string_view name, const std::string_view help)
28 : MetricBase(MetricType::Info, name, help) {}
29
30 explicit Info(const InfoSpec& spec) : MetricBase(MetricType::Info, spec.name, spec.help) {
31 core_->base_labels = spec.labels;
32 core_->const_labels = spec.labels;
33 core_->base_display = spec.display;
34 core_->display = spec.display;
35 }
36
37 explicit Info(std::shared_ptr<MetricCore> core) : MetricBase(std::move(core)) {}
38
40 void set(const std::initializer_list<Label> labels) const noexcept {
41 const std::vector<Label> owned(labels);
42 emit(owned);
43 }
44
46 void set(const Labels& labels) const noexcept {
47 const auto [adapter, handle] = this->bind();
48 adapter->set_info(handle, labels.view());
49 }
50
51 [[nodiscard]] Info labels(const Labels& dynamic) const noexcept {
52 return make_child(dynamic);
53 }
54
55private:
56 void emit(const std::vector<Label>& labels) const noexcept {
57 const auto [adapter, handle] = this->bind();
58 adapter->set_info(handle, std::span<const Label>(labels));
59 }
60};
61
62} // namespace prom
An info metric: a single sample whose labels carry the payload (build version, commit,...
Definition info.hpp:25
Info(std::shared_ptr< MetricCore > core)
Definition info.hpp:37
Info(const InfoSpec &spec)
Definition info.hpp:30
Info labels(const Labels &dynamic) const noexcept
Definition info.hpp:51
Info(const std::string_view name, const std::string_view help)
Definition info.hpp:27
void set(const Labels &labels) const noexcept
Set the info label payload from a Labels set.
Definition info.hpp:46
void set(const std::initializer_list< Label > labels) const noexcept
Set the info label payload from a braced list.
Definition info.hpp:40
An immutable-by-convention set of labels, kept sorted by name with duplicates collapsed last-wins.
Definition labels.hpp:55
CRTP base shared by every metric type.
Definition metric_base.hpp:377
Info make_child(const Labels &dynamic) const noexcept
Resolve a labeled child of the same metric type.
Definition metric_base.hpp:458
std::string_view name() const noexcept
The metric's fully-qualified name.
Definition metric_base.hpp:380
const std::shared_ptr< MetricCore > & core() const noexcept
Definition metric_base.hpp:449
std::shared_ptr< MetricCore > core_
Definition metric_base.hpp:530
Binding bind() const noexcept
Resolve the adapter and backend handle this metric should record against.
Definition metric_base.hpp:435
MetricCore (the shared per-series state) and the CRTP MetricBase that gives every metric type value s...
Definition adapter.hpp:24
MetricType
The OpenMetrics / Prometheus metric kinds prom understands.
Definition unit.hpp:15
Declarative description of an info metric.
Definition info.hpp:16
comms::DisplayInfo display
Definition info.hpp:20
std::string_view help
Definition info.hpp:18
Labels labels
Constant labels carried alongside the info set.
Definition info.hpp:19
std::string_view name
Definition info.hpp:17