Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
platform_metrics_collector.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
30#include <chrono>
31#include <cstdint>
32#include <memory>
33#include <string>
34#include <unordered_map>
35#include <vector>
36
39#include "collector_base.h"
40
41namespace kcenon {
42namespace monitoring {
43
44// =============================================================================
45// Metrics structures
46// =============================================================================
47
53 std::string name;
54 std::string version;
55 std::string architecture;
56 bool available{false};
57};
58
64 int64_t uptime_seconds{0};
65 int64_t idle_seconds{0};
66 int64_t boot_timestamp{0};
67 bool available{false};
68};
69
75 uint64_t total_switches{0};
76 uint64_t voluntary_switches{0};
78 double switches_per_second{0.0};
79 bool available{false};
80};
81
87 uint64_t established{0};
88 uint64_t syn_sent{0};
89 uint64_t syn_recv{0};
90 uint64_t fin_wait1{0};
91 uint64_t fin_wait2{0};
92 uint64_t time_wait{0};
93 uint64_t close_wait{0};
94 uint64_t listen{0};
95 uint64_t total{0};
96 bool available{false};
97};
98
104 uint64_t rx_buffer_size{0};
105 uint64_t tx_buffer_size{0};
106 uint64_t rx_buffer_used{0};
107 uint64_t tx_buffer_used{0};
108 bool available{false};
109};
110
116 uint64_t total_interrupts{0};
117 bool available{false};
118};
119
131
145
146// =============================================================================
147// Forward declarations
148// =============================================================================
149
150namespace platform {
151class metrics_provider;
152}
153
154// =============================================================================
155// Platform info collector
156// =============================================================================
157
220
221// =============================================================================
222// Main collector
223// =============================================================================
224
251 public:
254 ~platform_metrics_collector() override = default;
255
260
261 // collector_plugin interface implementation
266 auto name() const -> std::string_view override { return "platform_metrics_collector"; }
267
272 auto collect() -> std::vector<metric> override;
273
278 auto interval() const -> std::chrono::milliseconds override { return collection_interval_; }
279
284 auto is_available() const -> bool override;
285
290 bool is_healthy() const { return is_available(); }
291
296 auto get_metric_types() const -> std::vector<std::string> override;
297
303 bool initialize(const config_map& config) override;
304
309 auto get_statistics() const -> stats_map override;
310
311 // Accessors
317
323
328 std::string get_platform_name() const;
329
335
336 private:
338
341
342 // Cached platform info (doesn't change during runtime)
345
346 // Collection interval
347 std::chrono::milliseconds collection_interval_{std::chrono::seconds(10)};
348 mutable std::mutex metrics_mutex_;
349
350 // Helper methods
351 void collect_platform_info_metrics(std::vector<metric>& metrics);
352 void collect_uptime_metrics(std::vector<metric>& metrics);
353 void collect_context_switch_metrics(std::vector<metric>& metrics);
354 void collect_tcp_metrics(std::vector<metric>& metrics);
355 void collect_socket_metrics(std::vector<metric>& metrics);
356 void collect_interrupt_metrics(std::vector<metric>& metrics);
357};
358
359} // namespace monitoring
360} // namespace kcenon
Pure virtual interface for metric collector plugins.
Platform data collector using platform abstraction layer.
platform_info_collector(platform_info_collector &&)=delete
platform_info_collector & operator=(const platform_info_collector &)=delete
platform_interrupt_info get_interrupt_stats() const
platform_info_collector & operator=(platform_info_collector &&)=delete
platform_tcp_info get_tcp_states() const
platform_socket_info get_socket_buffers() const
std::unique_ptr< platform::metrics_provider > provider_
platform_info_collector(const platform_info_collector &)=delete
platform_context_switches get_context_switches() const
Unified platform-agnostic metrics collector.
void collect_context_switch_metrics(std::vector< metric > &metrics)
void collect_socket_metrics(std::vector< metric > &metrics)
platform_metrics_collector(const platform_metrics_collector &)=delete
platform_metrics_collector & operator=(platform_metrics_collector &&)=delete
auto is_available() const -> bool override
void collect_tcp_metrics(std::vector< metric > &metrics)
void collect_platform_info_metrics(std::vector< metric > &metrics)
void collect_interrupt_metrics(std::vector< metric > &metrics)
bool initialize(const config_map &config) override
auto name() const -> std::string_view override
platform_metrics_collector(platform_metrics_config config)
platform_metrics_collector & operator=(const platform_metrics_collector &)=delete
auto get_statistics() const -> stats_map override
std::unique_ptr< platform_info_collector > collector_
auto get_metric_types() const -> std::vector< std::string > override
auto interval() const -> std::chrono::milliseconds override
void collect_uptime_metrics(std::vector< metric > &metrics)
auto collect() -> std::vector< metric > override
platform_metrics_collector(platform_metrics_collector &&)=delete
CRTP base class for metric collectors.
Plugin interface for metric collectors.
Adapter for metric types to support interface definitions.
std::unordered_map< std::string, double > stats_map
Type alias for statistics map.
std::unordered_map< std::string, std::string > config_map
Type alias for configuration map.
@ platform
Platform/system power domain.
double switches_per_second
Context switches per second.
uint64_t voluntary_switches
Voluntary context switches.
uint64_t involuntary_switches
Involuntary context switches.
Platform identification information.
bool available
Whether platform info is available.
std::string name
Platform name (linux, macos, windows, unknown)
std::string architecture
CPU architecture (if available)
std::string version
OS version string (if available)
Configuration for platform metrics collection.
bool collect_context_switches
Collect context switch metrics.
bool collect_socket_buffers
Collect socket buffer metrics.
std::chrono::system_clock::time_point timestamp
Platform TCP connection state information.
uint64_t established
ESTABLISHED connections.
int64_t boot_timestamp
Unix timestamp of last boot.
int64_t idle_seconds
Total idle time in seconds.
int64_t uptime_seconds
System uptime in seconds.
bool available
Whether uptime info is available.