Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
stats_interface.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
15#pragma once
16
17#include "stats_snapshot.h"
18#include <string>
19#include <string_view>
20#include <unordered_map>
21#include <variant>
22
24
30using stats_value = std::variant<
31 std::int64_t,
32 double,
33 std::string,
34 bool
35>;
36
73class IStats {
74public:
75 virtual ~IStats() = default;
76
91 [[nodiscard]] virtual auto get_stats() const -> std::unordered_map<std::string, stats_value> = 0;
92
101 [[nodiscard]] virtual auto to_json() const -> std::string = 0;
102
111 [[nodiscard]] virtual auto name() const -> std::string_view = 0;
112
121 [[nodiscard]] virtual auto get_snapshot() const -> stats_snapshot
122 {
123 return stats_snapshot{
124 .component_name = std::string(name()),
125 .timestamp = std::chrono::system_clock::now(),
126 .values = get_stats()
127 };
128 }
129};
130
131} // namespace kcenon::common::interfaces
Interface for components that expose statistics.
virtual auto to_json() const -> std::string=0
Get statistics as JSON string.
virtual auto name() const -> std::string_view=0
Get component name for identification.
virtual auto get_snapshot() const -> stats_snapshot
Get a complete statistics snapshot with metadata.
virtual auto get_stats() const -> std::unordered_map< std::string, stats_value >=0
Get current statistics as key-value pairs.
std::variant< std::int64_t, double, std::string, bool > stats_value
Type-safe value type for statistics.
Value type for statistics snapshots.
Point-in-time snapshot of component statistics.