27#include <unordered_map>
31 #include <mach/mach.h>
32 #include <mach/mach_host.h>
33 #include <mach/processor_info.h>
34 #include <mach/vm_map.h>
35 #include <sys/sysctl.h>
36 #include <sys/types.h>
38 #include <sys/sysinfo.h>
41 #ifndef WIN32_LEAN_AND_MEAN
42 #define WIN32_LEAN_AND_MEAN
53 #pragma comment(lib, "ws2_32.lib")
54 #pragma comment(lib, "iphlpapi.lib")
60namespace kcenon {
namespace monitoring {
76 std::chrono::milliseconds
interval = std::chrono::seconds(10);
300 bool initialize(
const std::unordered_map<std::string, std::string>& config)
override;
302 std::string
get_name()
const override {
return "system_resource_collector"; }
330 template <
typename Duration>
343 template <
typename Duration>
399 const std::unordered_map<std::string, std::string>& labels = {})
const;
480 void add_alert(std::vector<alert>& alerts,
const std::string& resource,
481 alert::severity level,
double value,
double threshold,
const std::string& message);
void check_swap_usage(std::vector< alert > &alerts, const system_resources &resources)
resource_threshold_monitor(const thresholds &config)
std::vector< alert > get_alert_history(size_t max_count=100) const
const size_t max_history_size_
std::vector< alert > check_thresholds(const system_resources &resources)
std::mutex history_mutex_
void check_memory_usage(std::vector< alert > &alerts, const system_resources &resources)
void update_thresholds(const thresholds &config)
std::vector< alert > alert_history_
void check_disk_usage(std::vector< alert > &alerts, const system_resources &resources)
void check_cpu_usage(std::vector< alert > &alerts, const system_resources &resources)
thresholds get_thresholds() const
void add_alert(std::vector< alert > &alerts, const std::string &resource, alert::severity level, double value, double threshold, const std::string &message)
std::chrono::steady_clock::time_point last_collection_time_
std::string get_os_info() const
void collect_disk_stats(system_resources &resources)
system_resources collect()
void collect_cpu_stats(system_resources &resources)
void collect_network_stats(system_resources &resources)
void collect_memory_stats(system_resources &resources)
network_stats last_network_stats_
std::string get_hostname() const
disk_stats last_disk_stats_
void collect_process_stats(system_resources &resources)
cpu_stats last_cpu_stats_
std::chrono::seconds get_uptime() const
uint64_t last_context_switches_total_
void add_disk_metrics(std::vector< metric > &metrics, const system_resources &resources)
void configure_load_history(size_t max_samples)
void add_network_metrics(std::vector< metric > &metrics, const system_resources &resources)
system_resource_collector(const system_metrics_config &config)
~system_resource_collector() override=default
bool initialize(const std::unordered_map< std::string, std::string > &config) override
system_metrics_config get_config() const
std::unordered_map< std::string, double > get_statistics() const override
system_resources get_last_resources() const
void add_memory_metrics(std::vector< metric > &metrics, const system_resources &resources)
bool is_healthy() const override
bool collect_process_metrics_
bool is_load_history_enabled() const
load_average_statistics get_all_load_statistics() const
std::string get_name() const override
std::unique_ptr< system_info_collector > collector_
void add_cpu_metrics(std::vector< metric > &metrics, const system_resources &resources)
system_resource_collector()
bool enable_load_history_
std::atomic< size_t > collection_count_
std::shared_ptr< system_resources > last_resources_
std::vector< load_average_sample > get_load_history(Duration duration) const
bool collect_cpu_metrics_
std::atomic< int64_t > init_time_ns_
bool collect_network_metrics_
std::atomic< size_t > collection_errors_
void set_config(const system_metrics_config &config)
std::vector< std::string > get_metric_types() const override
load_average_statistics get_load_statistics(Duration duration) const
void add_process_metrics(std::vector< metric > &metrics, const system_resources &resources)
metric create_metric(const std::string &name, double value, const std::string &unit="", const std::unordered_map< std::string, std::string > &labels={}) const
std::vector< load_average_sample > get_all_load_history() const
std::unique_ptr< load_average_history > load_history_
std::vector< metric > collect() override
bool collect_memory_metrics_
bool collect_disk_metrics_
Plugin-based metric collector with dynamic discovery and registration.
Statistics for load average history.
Basic metric structure for interface compatibility.
std::chrono::steady_clock::time_point timestamp
double memory_usage_critical
double disk_usage_critical
double swap_usage_critical
double cpu_usage_critical
std::chrono::milliseconds interval
size_t load_history_max_samples
struct kcenon::monitoring::system_resources::cpu_metrics::load_average load
size_t write_bytes_per_sec
size_t read_bytes_per_sec
struct kcenon::monitoring::system_resources::disk_metrics::io_throughput io
struct kcenon::monitoring::system_resources::memory_metrics::swap_info swap
size_t tx_packets_per_sec
size_t rx_packets_per_sec
size_t open_file_descriptors
struct kcenon::monitoring::system_resources::memory_metrics memory
struct kcenon::monitoring::system_resources::cpu_metrics cpu
struct kcenon::monitoring::system_resources::process_metrics process
struct kcenon::monitoring::system_resources::disk_metrics disk
struct kcenon::monitoring::system_resources::network_metrics network
struct kcenon::monitoring::system_resources::context_switch_metrics context_switches
Generic time-series buffer for metric history tracking.