Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
interrupt_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
21#include <atomic>
22#include <chrono>
23#include <cstdint>
24#include <memory>
25#include <string>
26#include <unordered_map>
27#include <vector>
28
31
32namespace kcenon {
33namespace monitoring {
34
40 uint32_t cpu_id{0};
41 uint64_t interrupt_count{0};
42 double interrupts_per_sec{0.0};
43};
44
50 uint64_t interrupts_total{0};
51 double interrupts_per_sec{0.0};
54 std::vector<cpu_interrupt_info> per_cpu;
55 bool metrics_available{false};
57 std::chrono::system_clock::time_point timestamp;
58};
59
60// Forward declaration
61namespace platform {
62class metrics_provider;
63} // namespace platform
64
73 public:
76
77 // Non-copyable, non-moveable due to internal state
82
88
94
95 private:
96 std::unique_ptr<platform::metrics_provider> provider_;
97
98 // Previous sample for rate calculation
101 std::chrono::system_clock::time_point prev_timestamp_;
103};
104
112 public:
114 ~interrupt_collector() override = default;
115
116 // Non-copyable, non-moveable due to internal state
121
122 // collector_plugin implementation
123 auto name() const -> std::string_view override { return "interrupt_collector"; }
124 auto collect() -> std::vector<metric> override;
125 auto interval() const -> std::chrono::milliseconds override { return std::chrono::seconds(15); }
126 auto is_available() const -> bool override;
127 auto get_metric_types() const -> std::vector<std::string> override;
128
129 auto get_metadata() const -> plugin_metadata override {
130 return plugin_metadata{
131 .name = name(),
132 .description = "Hardware and software interrupt statistics",
133 .category = plugin_category::platform,
134 .version = "1.0.0",
135 .dependencies = {},
136 .requires_platform_support = true
137 };
138 }
139
147 auto initialize(const config_map& config) -> bool override;
148
153 auto get_statistics() const -> stats_map override;
154
160
166
167 private:
169
170 // Configuration
171 bool enabled_{true};
172 bool collect_per_cpu_{false};
174
175 // Last metrics cache
177
178 // Statistics
179 std::atomic<size_t> collection_count_{0};
180 std::atomic<size_t> collection_errors_{0};
181
182 // Helper methods
183 void add_interrupt_metrics(std::vector<metric>& metrics, const interrupt_metrics& data);
184};
185
186} // namespace monitoring
187} // namespace kcenon
Pure virtual interface for metric collector plugins.
Hardware and software interrupt statistics monitoring collector.
interrupt_collector(interrupt_collector &&)=delete
interrupt_collector & operator=(interrupt_collector &&)=delete
auto collect() -> std::vector< metric > override
Collect current metrics from this plugin.
auto name() const -> std::string_view override
Get the unique name of this plugin.
interrupt_collector & operator=(const interrupt_collector &)=delete
interrupt_collector(const interrupt_collector &)=delete
auto initialize(const config_map &config) -> bool override
auto is_available() const -> bool override
Check if this plugin is available on the current system.
auto get_metadata() const -> plugin_metadata override
Get plugin metadata.
auto get_metric_types() const -> std::vector< std::string > override
Get supported metric types.
auto get_statistics() const -> stats_map override
auto interval() const -> std::chrono::milliseconds override
Get the collection interval for this plugin.
void add_interrupt_metrics(std::vector< metric > &metrics, const interrupt_metrics &data)
interrupt_metrics get_last_metrics() const
std::unique_ptr< interrupt_info_collector > collector_
Interrupt data collector using platform abstraction layer.
interrupt_info_collector(const interrupt_info_collector &)=delete
interrupt_info_collector & operator=(interrupt_info_collector &&)=delete
std::chrono::system_clock::time_point prev_timestamp_
interrupt_info_collector & operator=(const interrupt_info_collector &)=delete
std::unique_ptr< platform::metrics_provider > provider_
interrupt_info_collector(interrupt_info_collector &&)=delete
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.
@ platform
Platform-specific (VM, uptime, interrupts)
std::unordered_map< std::string, std::string > config_map
Type alias for configuration map.
@ platform
Platform/system power domain.
uint64_t interrupt_count
Total interrupts on this CPU.
double interrupts_per_sec
Interrupt rate on this CPU.
Aggregated interrupt statistics for the system.
std::vector< cpu_interrupt_info > per_cpu
Per-CPU breakdown (optional)
uint64_t interrupts_total
Total hardware interrupt count.
double interrupts_per_sec
Hardware interrupt rate (gauge)
bool metrics_available
Whether interrupt metrics are available.
double soft_interrupts_per_sec
Soft interrupt rate (Linux only)
bool soft_interrupts_available
Whether soft interrupt metrics are available.
uint64_t soft_interrupts_total
Total soft interrupts (Linux only)
std::chrono::system_clock::time_point timestamp
Reading timestamp.
Metadata describing a collector plugin.