Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
metrics_provider.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
5#pragma once
6
23#include <chrono>
24#include <cstdint>
25#include <memory>
26#include <string>
27#include <vector>
28
29// Forward declarations for existing types
32
33namespace kcenon {
34namespace monitoring {
35namespace platform {
36
42 int64_t uptime_seconds{0};
43 int64_t idle_seconds{0};
44 std::chrono::system_clock::time_point boot_time;
45 bool available{false};
46};
47
53 uint64_t total_switches{0};
54 uint64_t voluntary_switches{0};
56 double switches_per_second{0.0};
57 bool available{false};
58 std::chrono::system_clock::time_point timestamp;
59};
60
65struct fd_info {
66 uint64_t open_fds{0};
67 uint64_t max_fds{0};
68 double usage_percent{0.0};
69 bool available{false};
70};
71
76struct inode_info {
77 uint64_t total_inodes{0};
78 uint64_t used_inodes{0};
79 uint64_t free_inodes{0};
80 double usage_percent{0.0};
81 std::string filesystem;
82 bool available{false};
83};
84
90 uint64_t established{0};
91 uint64_t syn_sent{0};
92 uint64_t syn_recv{0};
93 uint64_t fin_wait1{0};
94 uint64_t fin_wait2{0};
95 uint64_t time_wait{0};
96 uint64_t close_wait{0};
97 uint64_t last_ack{0};
98 uint64_t listen{0};
99 uint64_t closing{0};
100 uint64_t total{0};
101 bool available{false};
102};
103
109 uint64_t rx_buffer_size{0};
110 uint64_t tx_buffer_size{0};
111 uint64_t rx_buffer_used{0};
112 uint64_t tx_buffer_used{0};
113 bool available{false};
114};
115
121 std::string name;
122 uint64_t count{0};
123 uint64_t irq_number{0};
124 bool available{false};
125};
126
132 double power_watts{0.0};
133 double voltage_volts{0.0};
134 double current_amps{0.0};
135 std::string source;
136 bool available{false};
137};
138
143struct gpu_info {
144 std::string name;
145 std::string vendor;
146 double usage_percent{0.0};
147 double memory_used_mb{0.0};
148 double memory_total_mb{0.0};
150 double power_watts{0.0};
151 bool available{false};
152};
153
159 bool firewall_enabled{false};
161 uint64_t active_sessions{0};
162 std::string security_level;
163 bool available{false};
164};
165
175 public:
176 virtual ~metrics_provider() = default;
177
178 // Non-copyable, non-moveable
183
188 static std::unique_ptr<metrics_provider> create();
189
194 virtual std::string get_platform_name() const = 0;
195
196 // =========================================================================
197 // Battery Metrics
198 // =========================================================================
199
204 virtual bool is_battery_available() const = 0;
205
210 virtual std::vector<battery_reading> get_battery_readings() = 0;
211
212 // =========================================================================
213 // Temperature Metrics
214 // =========================================================================
215
220 virtual bool is_temperature_available() const = 0;
221
226 virtual std::vector<temperature_reading> get_temperature_readings() = 0;
227
228 // =========================================================================
229 // Uptime Metrics
230 // =========================================================================
231
236 virtual uptime_info get_uptime() = 0;
237
238 // =========================================================================
239 // Context Switch Metrics
240 // =========================================================================
241
247
248 // =========================================================================
249 // File Descriptor Metrics
250 // =========================================================================
251
256 virtual fd_info get_fd_stats() = 0;
257
258 // =========================================================================
259 // Inode Metrics
260 // =========================================================================
261
266 virtual std::vector<inode_info> get_inode_stats() = 0;
267
268 // =========================================================================
269 // TCP State Metrics
270 // =========================================================================
271
277
278 // =========================================================================
279 // Socket Buffer Metrics
280 // =========================================================================
281
287
288 // =========================================================================
289 // Interrupt Metrics
290 // =========================================================================
291
296 virtual std::vector<interrupt_info> get_interrupt_stats() = 0;
297
298 // =========================================================================
299 // Power Metrics
300 // =========================================================================
301
306 virtual bool is_power_available() const = 0;
307
313
314 // =========================================================================
315 // GPU Metrics
316 // =========================================================================
317
322 virtual bool is_gpu_available() const = 0;
323
328 virtual std::vector<gpu_info> get_gpu_info() = 0;
329
330 // =========================================================================
331 // Security Metrics
332 // =========================================================================
333
339
340 protected:
341 metrics_provider() = default;
342};
343
344} // namespace platform
345} // namespace monitoring
346} // namespace kcenon
Battery status monitoring collector.
Abstract interface for platform-specific metrics collection.
metrics_provider(metrics_provider &&)=delete
virtual tcp_state_info get_tcp_states()=0
Get TCP connection state statistics.
virtual bool is_temperature_available() const =0
Check if temperature monitoring is available.
virtual bool is_battery_available() const =0
Check if battery monitoring is available.
virtual std::string get_platform_name() const =0
Get the platform name.
virtual std::vector< temperature_reading > get_temperature_readings()=0
Get temperature readings from all available sensors.
virtual socket_buffer_info get_socket_buffer_stats()=0
Get socket buffer statistics.
metrics_provider & operator=(metrics_provider &&)=delete
virtual power_info get_power_info()=0
Get power consumption information.
metrics_provider(const metrics_provider &)=delete
virtual bool is_gpu_available() const =0
Check if GPU monitoring is available.
virtual std::vector< battery_reading > get_battery_readings()=0
Get battery readings from all available batteries.
metrics_provider & operator=(const metrics_provider &)=delete
virtual context_switch_info get_context_switches()=0
Get context switch statistics.
virtual bool is_power_available() const =0
Check if power monitoring is available.
static std::unique_ptr< metrics_provider > create()
Create a platform-specific metrics provider.
virtual uptime_info get_uptime()=0
Get system uptime information.
virtual std::vector< inode_info > get_inode_stats()=0
Get inode statistics for all filesystems.
virtual fd_info get_fd_stats()=0
Get file descriptor statistics.
virtual std::vector< gpu_info > get_gpu_info()=0
Get GPU information and metrics.
virtual security_info get_security_info()=0
Get security-related metrics.
virtual std::vector< interrupt_info > get_interrupt_stats()=0
Get interrupt statistics.
@ platform
Platform/system power domain.
double switches_per_second
Context switches per second.
std::chrono::system_clock::time_point timestamp
uint64_t involuntary_switches
Involuntary context switches.
uint64_t voluntary_switches
Voluntary context switches.
uint64_t open_fds
Currently open file descriptors.
double usage_percent
FD usage percentage.
bool available
Whether info is available.
uint64_t max_fds
Maximum file descriptors allowed.
bool available
Whether info is available.
double power_watts
GPU power consumption in watts.
double memory_used_mb
GPU memory used in MB.
double temperature_celsius
GPU temperature in Celsius.
double usage_percent
GPU usage percentage.
double memory_total_mb
GPU memory total in MB.
bool available
Whether info is available.
double usage_percent
Inode usage percentage.
std::string filesystem
Filesystem path.
std::string name
Interrupt name/description.
std::string source
Power source (AC, battery, etc.)
double power_watts
Current power consumption in watts.
bool available
Whether info is available.
uint64_t failed_login_attempts
Failed login attempts.
uint64_t active_sessions
Active user sessions.
std::string security_level
Security level description.
bool available
Whether info is available.
bool firewall_enabled
Whether firewall is enabled.
uint64_t fin_wait2
FIN_WAIT2 connections.
uint64_t fin_wait1
FIN_WAIT1 connections.
uint64_t close_wait
CLOSE_WAIT connections.
uint64_t time_wait
TIME_WAIT connections.
uint64_t established
ESTABLISHED connections.
bool available
Whether uptime info is available.
int64_t uptime_seconds
System uptime in seconds.
std::chrono::system_clock::time_point boot_time
System boot time.
int64_t idle_seconds
Total idle time in seconds.
Hardware temperature monitoring collector.