Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
monitoring.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
25#pragma once
26
27#include <chrono>
28#include <concepts>
29#include <string>
30#include <string_view>
31#include <type_traits>
32#include <unordered_map>
33
34namespace kcenon::common {
35
36// Forward declarations
37namespace interfaces {
38using metric_labels = std::unordered_map<std::string, std::string>;
39} // namespace interfaces
40
41namespace concepts {
42
58template <typename T>
59concept CounterMetric = requires(T t,
60 std::string_view name,
61 double value,
62 const interfaces::metric_labels& labels) {
63 { t.increment(name, value, labels) } -> std::same_as<void>;
64};
65
81template <typename T>
82concept GaugeMetric = requires(T t,
83 std::string_view name,
84 double value,
85 const interfaces::metric_labels& labels) {
86 { t.gauge(name, value, labels) } -> std::same_as<void>;
87};
88
104template <typename T>
105concept HistogramMetric = requires(T t,
106 std::string_view name,
107 double value,
108 const interfaces::metric_labels& labels) {
109 { t.histogram(name, value, labels) } -> std::same_as<void>;
110};
111
127template <typename T>
128concept TimingMetric = requires(T t,
129 std::string_view name,
130 std::chrono::nanoseconds duration,
131 const interfaces::metric_labels& labels) {
132 { t.timing(name, duration, labels) } -> std::same_as<void>;
133};
134
154template <typename T>
159
175template <typename T>
176concept NamedImplementation = requires(const T t) {
177 { t.get_implementation_name() } -> std::convertible_to<std::string>;
178};
179
195template <typename T>
196concept MetricCollectorProviderLike = requires(T t, const std::string& prefix) {
197 { t.get_metric_collector() };
198 { t.create_metric_collector(prefix) };
199};
200
201} // namespace concepts
202} // namespace kcenon::common
A type that supports counter metric operations.
Definition monitoring.h:59
A type that supports gauge metric operations.
Definition monitoring.h:82
A type that supports histogram metric operations.
Definition monitoring.h:105
A complete metric collector type satisfying IMetricCollector interface.
Definition monitoring.h:155
A type that can provide metric collector instances.
Definition monitoring.h:196
A type that provides implementation name for debugging.
Definition monitoring.h:176
A type that supports timing metric operations.
Definition monitoring.h:128
std::unordered_map< std::string, std::string > metric_labels
Metric labels for dimensional data.
Definition monitoring.h:38
Core interfaces.
Definition adapter.h:21