-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7b335a
commit 5cd23e3
Showing
18 changed files
with
197 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <benchmark/benchmark.h> | ||
|
||
#include "prometheus/family.h" | ||
#include "prometheus/info.h" | ||
#include "prometheus/registry.h" | ||
|
||
static void BM_Info_Collect(benchmark::State& state) { | ||
using prometheus::BuildInfo; | ||
using prometheus::Info; | ||
using prometheus::Registry; | ||
Registry registry; | ||
auto& info_family = | ||
BuildInfo().Name("benchmark_info").Help("").Register(registry); | ||
auto& info = info_family.Add({}); | ||
|
||
while (state.KeepRunning()) { | ||
benchmark::DoNotOptimize(info.Collect()); | ||
}; | ||
} | ||
BENCHMARK(BM_Info_Collect); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#pragma once | ||
|
||
#include "prometheus/client_metric.h" | ||
#include "prometheus/detail/builder.h" // IWYU pragma: export | ||
#include "prometheus/detail/core_export.h" | ||
#include "prometheus/metric_type.h" | ||
|
||
namespace prometheus { | ||
|
||
/// \brief A info metric to represent textual information which should not | ||
/// change during process lifetime. | ||
/// | ||
/// This class represents the metric type info: | ||
/// https://github.com/OpenObservability/OpenMetrics/blob/98ae26c87b1c3bcf937909a880b32c8be643cc9b/specification/OpenMetrics.md#info | ||
|
||
/// Prometheus does not provide this type directly, it is used by emulating a | ||
/// gauge with value 1: https://prometheus.io/docs/concepts/metric_types/#gauge | ||
/// | ||
/// The value of the info cannot change. Example of infos are: | ||
/// - the application's version | ||
/// - revision control commit | ||
/// - version of the compiler | ||
/// | ||
/// The class is thread-safe. No concurrent call to any API of this type causes | ||
/// a data race. | ||
class PROMETHEUS_CPP_CORE_EXPORT Info { | ||
public: | ||
static const MetricType metric_type{MetricType::Info}; | ||
|
||
/// \brief Create a info. | ||
Info() = default; | ||
|
||
/// \brief Get the current value of the info. | ||
/// | ||
/// Collect is called by the Registry when collecting metrics. | ||
ClientMetric Collect() const; | ||
}; | ||
|
||
/// \brief Return a builder to configure and register a Info metric. | ||
/// | ||
/// @copydetails Family<>::Family() | ||
/// | ||
/// Example usage: | ||
/// | ||
/// \code | ||
/// auto registry = std::make_shared<Registry>(); | ||
/// auto& info_family = prometheus::BuildInfo() | ||
/// .Name("some_name") | ||
/// .Help("Additional description.") | ||
/// .Labels({{"key", "value"}}) | ||
/// .Register(*registry); | ||
/// | ||
/// ... | ||
/// \endcode | ||
/// | ||
/// \return An object of unspecified type T, i.e., an implementation detail | ||
/// except that it has the following members: | ||
/// | ||
/// - Name(const std::string&) to set the metric name, | ||
/// - Help(const std::string&) to set an additional description. | ||
/// - Labels(const Labels&) to assign a set of | ||
/// key-value pairs (= labels) to the metric. | ||
/// | ||
/// To finish the configuration of the Info metric, register it with | ||
/// Register(Registry&). | ||
PROMETHEUS_CPP_CORE_EXPORT detail::Builder<Info> BuildInfo(); | ||
|
||
} // namespace prometheus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ enum class MetricType { | |
Summary, | ||
Untyped, | ||
Histogram, | ||
Info, | ||
}; | ||
|
||
} // namespace prometheus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "prometheus/info.h" | ||
|
||
namespace prometheus { | ||
|
||
ClientMetric Info::Collect() const { | ||
ClientMetric metric; | ||
metric.info.value = 1; | ||
return metric; | ||
} | ||
|
||
} // namespace prometheus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.