Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
monitoring_concepts.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
25#pragma once
26
27#include <concepts>
28#include <functional>
29#include <memory>
30#include <string>
31#include <type_traits>
32#include <vector>
34
35#if KCENON_HAS_COMMON_SYSTEM
36#include <kcenon/common/concepts/concepts.h>
37#endif
38
39namespace kcenon::monitoring {
40namespace concepts {
41
57template <typename T>
58concept MetricValue = std::is_arithmetic_v<T>;
59
75template <typename T>
76concept MetricType =
77 std::is_class_v<T> && std::is_copy_constructible_v<T> && requires(const T t) {
78 { t.name } -> std::convertible_to<std::string>;
79 { t.value } -> std::convertible_to<double>;
80 };
81
97template <typename T>
98concept MetricSourceLike = requires(const T t) {
99 { t.get_current_metrics() };
100 { t.get_source_name() } -> std::convertible_to<std::string>;
101 { t.is_healthy() } -> std::convertible_to<bool>;
102};
103
118template <typename T>
119concept MetricCollectorLike = requires(T t) {
120 { t.collect_metrics() };
121 { t.is_collecting() } -> std::convertible_to<bool>;
122 { t.get_metric_types() };
123};
124
139template <typename T>
140concept ObserverLike = requires(T t) {
141 { t.on_metrics_updated(std::declval<std::vector<int>>()) };
142};
143
159template <typename T>
160concept MonitoringEventType = std::is_class_v<T> && std::is_copy_constructible_v<T>;
161
176template <typename H, typename E>
178 std::invocable<H, const E&> && std::is_void_v<std::invoke_result_t<H, const E&>>;
179
198template <typename F, typename M>
200 std::invocable<F, const M&> && std::convertible_to<std::invoke_result_t<F, const M&>, bool>;
201
219template <typename F, typename M>
220concept MetricTransformer = std::invocable<F, const M&>;
221
241template <typename T>
242concept ConfigValidatable = requires(const T t) {
243 { t.validate() };
244};
245
260template <typename T>
261concept StorageBackendLike = requires(T t) {
262 { t.store(std::declval<std::vector<int>>()) };
263 { t.is_connected() } -> std::convertible_to<bool>;
264};
265
280template <typename T>
281concept ExporterLike = requires(T t) {
282 { t.export_metrics(std::declval<std::vector<int>>()) };
283 { t.is_ready() } -> std::convertible_to<bool>;
284};
285
300template <typename T>
301concept HealthCheckable = requires(const T t) {
302 { t.is_healthy() } -> std::convertible_to<bool>;
303};
304
320template <typename T>
321concept TracingContextLike = requires(const T t) {
322 { t.get_trace_id() } -> std::convertible_to<std::string>;
323 { t.get_span_id() } -> std::convertible_to<std::string>;
324};
325
326} // namespace concepts
327} // namespace kcenon::monitoring
A configuration type that supports validation.
A type that can export metrics to external systems.
A type that supports health checking.
A type that can collect metrics from sources.
A callable that filters metrics based on criteria.
A type that can be used as a metric in the monitoring system.
A type that can be used as a metric value.
A callable that can handle monitoring events.
A type that can be used as a monitoring event.
A type that can observe metric updates.
A type that represents a tracing context.
Unified feature flags header for monitoring_system.