Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
temperature_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
18#include <atomic>
19#include <chrono>
20#include <cstdint>
21#include <memory>
22#include <mutex>
23#include <string>
24#include <unordered_map>
25#include <vector>
26
29
30namespace kcenon {
31namespace monitoring {
32
37enum class sensor_type {
38 unknown,
39 cpu,
40 gpu,
42 storage,
43 ambient,
44 other
45};
46
50inline std::string sensor_type_to_string(sensor_type type) {
51 switch (type) {
53 return "cpu";
55 return "gpu";
57 return "motherboard";
59 return "storage";
61 return "ambient";
63 return "other";
64 default:
65 return "unknown";
66 }
67}
68
74 std::string id;
75 std::string name;
76 std::string zone_path;
78};
79
86 double temperature_celsius{0.0};
90 bool is_critical{false};
91 bool is_warning{false};
92 std::chrono::system_clock::time_point timestamp;
93};
94
95// Forward declaration
96namespace platform {
97class metrics_provider;
98} // namespace platform
99
108 public:
111
112 // Non-copyable, non-moveable due to internal state
117
123
128 std::vector<temperature_sensor_info> enumerate_sensors();
129
134 std::vector<temperature_reading> read_all_temperatures();
135
136 private:
137 std::unique_ptr<platform::metrics_provider> provider_;
138};
139
149 public:
151 ~temperature_collector() override = default;
152
153 // Non-copyable, non-moveable due to internal state
158
159 // collector_plugin implementation
160 auto name() const -> std::string_view override { return "temperature"; }
161 auto collect() -> std::vector<metric> override;
162 auto interval() const -> std::chrono::milliseconds override { return std::chrono::seconds(5); }
163 auto is_available() const -> bool override;
164 auto get_metric_types() const -> std::vector<std::string> override;
165
166 auto get_metadata() const -> plugin_metadata override {
167 return plugin_metadata{
168 .name = name(),
169 .description = "Hardware temperature metrics from thermal sensors",
170 .category = plugin_category::hardware,
171 .version = "1.0.0",
172 .dependencies = {},
173 .requires_platform_support = true
174 };
175 }
176
177 auto initialize(const config_map& config) -> bool override;
178 void shutdown() override {}
179 auto get_statistics() const -> stats_map override;
180
186
192
193 private:
195
196 // Configuration
197 bool enabled_{true};
200
201 // Statistics
202 mutable std::mutex stats_mutex_;
203 std::atomic<size_t> collection_count_{0};
204 std::atomic<size_t> collection_errors_{0};
205 std::atomic<size_t> sensors_found_{0};
206 std::vector<temperature_reading> last_readings_;
207
208 // Helper methods
209 metric create_metric(const std::string& name, double value, const temperature_reading& reading,
210 const std::string& unit = "") const;
211 void add_sensor_metrics(std::vector<metric>& metrics, const temperature_reading& reading);
212};
213
214} // namespace monitoring
215} // namespace kcenon
Pure virtual interface for metric collector plugins.
Hardware temperature monitoring collector implementing collector_plugin interface.
std::unique_ptr< temperature_info_collector > collector_
auto name() const -> std::string_view override
Get the unique name of this plugin.
void shutdown() override
Shutdown plugin and release resources.
temperature_collector & operator=(const temperature_collector &)=delete
temperature_collector(temperature_collector &&)=delete
auto get_metric_types() const -> std::vector< std::string > override
Get supported metric types.
std::vector< temperature_reading > get_last_readings() const
std::vector< temperature_reading > last_readings_
auto interval() const -> std::chrono::milliseconds override
Get the collection interval for this plugin.
auto collect() -> std::vector< metric > override
Collect current metrics from this plugin.
void add_sensor_metrics(std::vector< metric > &metrics, const temperature_reading &reading)
auto get_metadata() const -> plugin_metadata override
Get plugin metadata.
metric create_metric(const std::string &name, double value, const temperature_reading &reading, const std::string &unit="") const
auto initialize(const config_map &config) -> bool override
Initialize plugin with configuration.
temperature_collector & operator=(temperature_collector &&)=delete
temperature_collector(const temperature_collector &)=delete
auto get_statistics() const -> stats_map override
Get plugin statistics.
auto is_available() const -> bool override
Check if this plugin is available on the current system.
Temperature data collector using platform abstraction layer.
std::vector< temperature_sensor_info > enumerate_sensors()
temperature_info_collector(temperature_info_collector &&)=delete
temperature_info_collector(const temperature_info_collector &)=delete
temperature_info_collector & operator=(const temperature_info_collector &)=delete
std::vector< temperature_reading > read_all_temperatures()
std::unique_ptr< platform::metrics_provider > provider_
temperature_info_collector & operator=(temperature_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.
std::string sensor_type_to_string(sensor_type type)
Convert sensor_type to string representation.
@ hardware
Hardware sensors (GPU, temperature, battery, power)
std::unordered_map< std::string, std::string > config_map
Type alias for configuration map.
sensor_type
Type of temperature sensor.
@ gpu
GPU temperature sensor.
@ motherboard
Motherboard/chipset sensor.
@ unknown
Unknown sensor type.
@ cpu
CPU temperature sensor.
@ storage
Storage device sensor.
@ ambient
Ambient/case temperature.
@ platform
Platform/system power domain.
@ cpu
CPU power domain (RAPL)
Basic metric structure for interface compatibility.
Metadata describing a collector plugin.
A single temperature reading from a sensor.
double critical_threshold_celsius
Critical temperature threshold (if available)
std::chrono::system_clock::time_point timestamp
Reading timestamp.
bool thresholds_available
Whether thresholds are available.
double warning_threshold_celsius
Warning threshold (if available)
bool is_warning
True if temperature exceeds warning threshold.
double temperature_celsius
Current temperature in Celsius.
temperature_sensor_info sensor
Sensor information.
bool is_critical
True if temperature exceeds critical threshold.
Information about a temperature sensor.
sensor_type type
Sensor type classification.
std::string zone_path
Platform-specific path (e.g., /sys/class/thermal/thermal_zone0)
std::string id
Unique sensor identifier.
std::string name
Human-readable sensor name.