userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
prometheus.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/utils/statistics/prometheus.hpp
4
/// @brief Statistics output in Prometheus format.
5
/// @ingroup userver_universal
6
7
#
include
<
string
>
8
#
include
<
string_view
>
9
10
#
include
<
userver
/
utils
/
statistics
/
request
.
hpp
>
11
#
include
<
userver
/
utils
/
statistics
/
visit
.
hpp
>
12
13
USERVER_NAMESPACE_BEGIN
14
15
namespace
utils
::
statistics
{
16
17
namespace
impl {
18
19
// The metric name specifies the general feature of a system that is measured
20
// (e.g. http_requests_total - the total number of HTTP requests received).
21
// It may contain ASCII letters and digits, as well as underscores and colons.
22
// It must match the regex [a-zA-Z_][a-zA-Z0-9_]*.
23
std::string ToPrometheusName(std::string_view data);
24
25
// Label names may contain ASCII letters, numbers, as well as underscores.
26
// They must match the regex [a-zA-Z_][a-zA-Z0-9_]*.
27
// Label names beginning with __ are reserved for internal use.
28
std::string ToPrometheusLabel(std::string_view name);
29
30
}
// namespace impl
31
32
/// Output `statistics` in Prometheus format, each metric has `gauge` type.
33
std::string
ToPrometheusFormat
(
WriterFuncRef
writer,
const
Request& request
=
{
}
);
34
35
/// @overload
36
std
::
string
ToPrometheusFormat
(
const
HasWriterSupport
auto
&
metric
,
const
Request
&
request
= {}) {
37
return
ToPrometheusFormat
([&
metric
](
Writer
&
writer
) {
writer
=
metric
; },
request
);
38
}
39
40
/// Output `statistics` in Prometheus format, without metric types.
41
std::string
ToPrometheusFormatUntyped
(
WriterFuncRef
writer,
const
Request& request
=
{
}
);
42
43
/// @overload
44
std
::
string
ToPrometheusFormatUntyped
(
const
HasWriterSupport
auto
&
metric
,
const
Request
&
request
= {}) {
45
return
ToPrometheusFormatUntyped
([&
metric
](
Writer
&
writer
) {
writer
=
metric
; },
request
);
46
}
47
48
}
// namespace utils::statistics
49
50
USERVER_NAMESPACE_END
userver
utils
statistics
prometheus.hpp
Generated on
for userver by
Doxygen
1.17.0