userver: userver/utils/statistics/prometheus.hpp Source File
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
6#include <string>
7#include <string_view>
8
9#include <userver/utils/statistics/request.hpp>
10#include <userver/utils/statistics/storage.hpp>
11#include <userver/utils/statistics/writer.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15namespace utils::statistics {
16
17namespace 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_]*.
23std::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.
28std::string ToPrometheusLabel(std::string_view name);
29
30} // namespace impl
31
32/// Output `statistics` in Prometheus format, each metric has `gauge` type.
33std::string ToPrometheusFormat(const Storage& statistics, const Request& request = {});
34
35std::string ToPrometheusFormat(WriterFuncRef writer, const Request& request = {});
36
37/// Output `statistics` in Prometheus format, without metric types.
38std::string ToPrometheusFormatUntyped(const Storage& statistics, const Request& request = {});
39
40std::string ToPrometheusFormatUntyped(WriterFuncRef writer, const Request& request = {});
41
42} // namespace utils::statistics
43
44USERVER_NAMESPACE_END