Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
collector_plugin.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
50#include <chrono>
51#include <memory>
52#include <string>
53#include <string_view>
54#include <vector>
55
58
59namespace kcenon {
60namespace monitoring {
61
69enum class plugin_category {
70 system,
71 hardware,
72 platform,
73 network,
74 process,
75 custom
76};
77
86 std::string_view name;
87 std::string_view description;
89 std::string_view version;
90 std::vector<std::string_view> dependencies;
92};
93
140public:
141 virtual ~collector_plugin() = default;
142
152 virtual auto name() const -> std::string_view = 0;
153
165 virtual auto collect() -> std::vector<metric> = 0;
166
177 virtual auto interval() const -> std::chrono::milliseconds = 0;
178
191 virtual auto is_available() const -> bool = 0;
192
200 virtual auto get_metadata() const -> plugin_metadata {
201 return plugin_metadata{
202 .name = name(),
203 .description = "",
204 .category = plugin_category::custom,
205 .version = "1.0.0",
206 .dependencies = {},
207 .requires_platform_support = false
208 };
209 }
210
219 virtual auto initialize(const config_map& /* config */) -> bool {
220 return true;
221 }
222
229 virtual void shutdown() {}
230
237 virtual auto get_statistics() const -> stats_map {
238 return {};
239 }
240
247 virtual auto get_metric_types() const -> std::vector<std::string> = 0;
248};
249
256using plugin_factory_fn = std::unique_ptr<collector_plugin> (*)();
257
258} // namespace monitoring
259} // namespace kcenon
Pure virtual interface for metric collector plugins.
virtual auto get_metric_types() const -> std::vector< std::string >=0
Get supported metric types.
virtual auto get_statistics() const -> stats_map
Get plugin statistics.
virtual auto initialize(const config_map &) -> bool
Initialize plugin with configuration.
virtual auto interval() const -> std::chrono::milliseconds=0
Get the collection interval for this plugin.
virtual auto collect() -> std::vector< metric >=0
Collect current metrics from this plugin.
virtual void shutdown()
Shutdown plugin and release resources.
virtual auto is_available() const -> bool=0
Check if this plugin is available on the current system.
virtual auto get_metadata() const -> plugin_metadata
Get plugin metadata.
virtual auto name() const -> std::string_view=0
Get the unique name of this plugin.
CRTP base class 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::unique_ptr< collector_plugin >(*)() plugin_factory_fn
Type alias for plugin factory function.
plugin_category
Categorization of collector plugins.
@ hardware
Hardware sensors (GPU, temperature, battery, power)
@ system
System integration (threads, loggers, containers)
@ custom
User-defined plugins.
@ network
Network metrics (connectivity, bandwidth)
std::unordered_map< std::string, std::string > config_map
Type alias for configuration map.
@ platform
Platform/system power domain.
Basic metric structure for interface compatibility.
Metadata describing a collector plugin.
std::vector< std::string_view > dependencies
Required dependencies.
std::string_view version
Plugin version (semver)
std::string_view name
Unique plugin identifier.
std::string_view description
Human-readable description.
plugin_category category
Plugin category.
bool requires_platform_support
Platform-specific plugin.