LogIt++
Header-only, macro-first C++ logging library
Loading...
Searching...
No Matches
PrometheusMetricBuilders.hpp
Go to the documentation of this file.
1#pragma once
2#ifndef LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_LOGGERS_PROMETHEUS_PROMETHEUSMETRICBUILDERS_HPP_INCLUDED
3#define LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_LOGGERS_PROMETHEUS_PROMETHEUSMETRICBUILDERS_HPP_INCLUDED
4
7
9
10#include <string>
11#include <utility>
12#include <vector>
13
14namespace logit {
15
18 const std::string& name,
19 const std::string& value) {
20 PrometheusLabel label;
21 label.name = name;
22 label.value = value;
23 return label;
24 }
25
28 const std::string& name,
29 double value,
30 std::vector<PrometheusLabel> labels = {},
31 int64_t timestamp_ms = 0) {
32 PrometheusSample s;
33 s.name = name;
34 s.value = value;
35 s.labels = std::move(labels);
36 s.timestamp_ms = timestamp_ms;
37 return s;
38 }
39
42 const std::string& name,
43 const std::string& help,
44 double value) {
46 mf.name = name;
47 mf.help = help;
49 mf.samples.push_back(make_prometheus_sample(name, value));
50 return mf;
51 }
52
55 const std::string& name,
56 const std::string& help,
57 double value,
58 std::vector<PrometheusLabel> labels) {
60 mf.name = name;
61 mf.help = help;
63 mf.samples.push_back(make_prometheus_sample(name, value, std::move(labels)));
64 return mf;
65 }
66
69 const std::string& name,
70 const std::string& help,
71 double value) {
73 mf.name = name;
74 mf.help = help;
76 mf.samples.push_back(make_prometheus_sample(name, value));
77 return mf;
78 }
79
82 const std::string& name,
83 const std::string& help,
84 double value,
85 std::vector<PrometheusLabel> labels) {
87 mf.name = name;
88 mf.help = help;
90 mf.samples.push_back(make_prometheus_sample(name, value, std::move(labels)));
91 return mf;
92 }
93
96 const std::string& name,
97 const std::string& help,
98 double value) {
100 mf.name = name;
101 mf.help = help;
103 mf.samples.push_back(make_prometheus_sample(name, value));
104 return mf;
105 }
106
109 const std::string& name,
110 const std::string& help,
111 double value,
112 std::vector<PrometheusLabel> labels) {
114 mf.name = name;
115 mf.help = help;
117 mf.samples.push_back(make_prometheus_sample(name, value, std::move(labels)));
118 return mf;
119 }
120
123 std::vector<PrometheusMetricFamily>& families,
124 const std::string& name,
125 const std::string& help,
126 double value,
127 std::vector<PrometheusLabel> labels = {}) {
128 families.push_back(make_prometheus_counter(name, help, value, std::move(labels)));
129 }
130
133 std::vector<PrometheusMetricFamily>& families,
134 const std::string& name,
135 const std::string& help,
136 double value,
137 std::vector<PrometheusLabel> labels = {}) {
138 families.push_back(make_prometheus_gauge(name, help, value, std::move(labels)));
139 }
140
143 std::vector<PrometheusMetricFamily>& families,
144 const std::string& name,
145 const std::string& help,
146 double value,
147 std::vector<PrometheusLabel> labels = {}) {
148 families.push_back(make_prometheus_untyped(name, help, value, std::move(labels)));
149 }
150
151} // namespace logit
152
153#endif // LOGIT_CPP_HEADER_LOGIT_CPP_LOGIT_LOGGERS_PROMETHEUS_PROMETHEUSMETRICBUILDERS_HPP_INCLUDED
Defines Prometheus text exposition format types and configuration.
The primary namespace for the LogIt++ library.
void add_prometheus_untyped(std::vector< PrometheusMetricFamily > &families, const std::string &name, const std::string &help, double value, std::vector< PrometheusLabel > labels={})
Append an Untyped metric family to the families vector (convenience for on_collect).
void add_prometheus_counter(std::vector< PrometheusMetricFamily > &families, const std::string &name, const std::string &help, double value, std::vector< PrometheusLabel > labels={})
Append a Counter metric family to the families vector (convenience for on_collect).
PrometheusLabel make_prometheus_label(const std::string &name, const std::string &value)
Create a single label pair.
void add_prometheus_gauge(std::vector< PrometheusMetricFamily > &families, const std::string &name, const std::string &help, double value, std::vector< PrometheusLabel > labels={})
Append a Gauge metric family to the families vector (convenience for on_collect).
PrometheusMetricFamily make_prometheus_gauge(const std::string &name, const std::string &help, double value)
Create a Gauge metric family with one unlabeled sample.
PrometheusMetricFamily make_prometheus_untyped(const std::string &name, const std::string &help, double value)
Create an Untyped metric family with one unlabeled sample.
PrometheusMetricFamily make_prometheus_counter(const std::string &name, const std::string &help, double value)
Create a Counter metric family with one unlabeled sample.
PrometheusSample make_prometheus_sample(const std::string &name, double value, std::vector< PrometheusLabel > labels={}, int64_t timestamp_ms=0)
Create a sample for a Prometheus metric family.
A single Prometheus label key-value pair.
A group of related samples sharing a name, help, and type.
std::vector< PrometheusSample > samples
Samples in this family.
std::string name
Metric family name.
PrometheusMetricType type
Metric type.
A single metric sample with optional labels and timestamp.