Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
uptime_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 double uptime_seconds{0.0};
41 int64_t boot_timestamp{0};
42 double idle_seconds{0.0};
43
44 bool metrics_available{false};
45 std::chrono::system_clock::time_point timestamp;
46};
47
48// Forward declaration
49namespace platform {
50class metrics_provider;
51} // namespace platform
52
61 public:
64
65 // Non-copyable, non-moveable due to internal state
70
76
82
83 private:
84 std::unique_ptr<platform::metrics_provider> provider_;
85};
86
95 public:
97 ~uptime_collector() override = default;
98
99 // Non-copyable, non-moveable due to internal state
104
105 // collector_plugin implementation
106 auto name() const -> std::string_view override { return "uptime"; }
107 auto collect() -> std::vector<metric> override;
108 auto interval() const -> std::chrono::milliseconds override { return std::chrono::seconds(30); }
109 auto is_available() const -> bool override;
110 auto get_metric_types() const -> std::vector<std::string> override;
111
112 auto get_metadata() const -> plugin_metadata override {
113 return plugin_metadata{
114 .name = name(),
115 .description = "System uptime metrics (boot time, uptime duration)",
116 .category = plugin_category::platform,
117 .version = "1.0.0",
118 .dependencies = {},
119 .requires_platform_support = true
120 };
121 }
122
129 auto initialize(const config_map& config) -> bool override;
130
135 auto get_statistics() const -> stats_map override;
136
142
148
149 private:
151
152 // Configuration
153 bool enabled_{true};
155
156 // Last metrics cache
158
159 // Statistics
160 std::atomic<size_t> collection_count_{0};
161 std::atomic<size_t> collection_errors_{0};
162
163 // Helper methods
164 void add_uptime_metrics(std::vector<metric>& metrics,
165 const uptime_metrics& uptime_data);
166};
167
168} // namespace monitoring
169} // namespace kcenon
Pure virtual interface for metric collector plugins.
System uptime monitoring collector implementing collector_plugin interface.
auto collect() -> std::vector< metric > override
Collect current metrics from this plugin.
uptime_metrics get_last_metrics() const
auto is_available() const -> bool override
Check if this plugin is available on the current system.
std::unique_ptr< uptime_info_collector > collector_
uptime_collector & operator=(uptime_collector &&)=delete
auto initialize(const config_map &config) -> bool override
auto get_metric_types() const -> std::vector< std::string > override
Get supported metric types.
uptime_collector & operator=(const uptime_collector &)=delete
uptime_collector(uptime_collector &&)=delete
auto get_metadata() const -> plugin_metadata override
Get plugin metadata.
auto name() const -> std::string_view override
Get the unique name of this plugin.
uptime_collector(const uptime_collector &)=delete
auto interval() const -> std::chrono::milliseconds override
Get the collection interval for this plugin.
auto get_statistics() const -> stats_map override
void add_uptime_metrics(std::vector< metric > &metrics, const uptime_metrics &uptime_data)
Uptime data collector using platform abstraction layer.
uptime_info_collector(uptime_info_collector &&)=delete
uptime_info_collector & operator=(const uptime_info_collector &)=delete
uptime_info_collector(const uptime_info_collector &)=delete
uptime_info_collector & operator=(uptime_info_collector &&)=delete
std::unique_ptr< platform::metrics_provider > provider_
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.
Metadata describing a collector plugin.
Aggregated uptime metrics for the system.
std::chrono::system_clock::time_point timestamp
Reading timestamp.
double uptime_seconds
Time since boot in seconds (gauge)
int64_t boot_timestamp
Unix timestamp of last boot (gauge)
double idle_seconds
Total idle time in seconds (Linux only)
bool metrics_available
Whether metrics are available.