|
Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
|
Thread-safe registry for managing collector plugins. More...
#include <collector_registry.h>

Public Member Functions | |
| auto | register_plugin (std::unique_ptr< collector_plugin > plugin) -> bool |
| Register a plugin instance. | |
| auto | unregister_plugin (std::string_view name) -> bool |
| Unregister a plugin by name. | |
| template<typename T > | |
| void | register_factory (std::string_view name) |
| Register a factory function for lazy instantiation. | |
| auto | get_plugin (std::string_view name) -> collector_plugin * |
| Get a plugin by name. | |
| auto | get_plugins () -> std::vector< collector_plugin * > |
| Get all registered plugins. | |
| auto | get_plugins_by_category (plugin_category category) -> std::vector< collector_plugin * > |
| Get plugins in a specific category. | |
| auto | initialize_all (const config_map &config={}) -> size_t |
| Initialize all registered plugins. | |
| void | shutdown_all () |
| Shutdown all registered plugins. | |
| auto | get_registry_stats () const -> std::map< std::string, size_t > |
| Get registry statistics. | |
| auto | has_plugin (std::string_view name) const -> bool |
| Check if a plugin is registered. | |
| auto | plugin_count () const -> size_t |
| Get the number of registered plugins. | |
| auto | load_plugin (std::string_view path) -> bool |
| Load a plugin from a shared library. | |
| auto | unload_plugin (std::string_view name) -> bool |
| Unload a dynamically loaded plugin. | |
| auto | get_plugin_loader_error () const -> std::string |
| Get the last error from plugin loader. | |
| void | clear () |
| Clear all plugins (for testing) | |
| collector_registry (const collector_registry &)=delete | |
| collector_registry & | operator= (const collector_registry &)=delete |
| collector_registry (collector_registry &&)=delete | |
| collector_registry & | operator= (collector_registry &&)=delete |
Static Public Member Functions | |
| static auto | instance () -> collector_registry & |
| Get the singleton instance. | |
Private Member Functions | |
| collector_registry ()=default | |
| ~collector_registry () | |
| auto | instantiate_from_factory (const std::string &name) -> bool |
| Instantiate a plugin from factory if needed. | |
Private Attributes | |
| std::unordered_map< std::string, std::unique_ptr< collector_plugin > > | plugins_ |
| std::unordered_map< std::string, plugin_factory_fn > | factories_ |
| std::unordered_map< std::string, bool > | initialized_ |
| std::mutex | mutex_ |
| bool | shutdown_ {false} |
| std::unique_ptr< dynamic_plugin_loader > | plugin_loader_ |
Thread-safe registry for managing collector plugins.
This class manages the lifecycle of all collector plugins in the system. It supports both eager registration (with plugin instances) and lazy registration (with factory functions).
Thread Safety:
Lifecycle:
Definition at line 82 of file collector_registry.h.
|
delete |
|
delete |
|
privatedefault |
|
private |
| void kcenon::monitoring::collector_registry::clear | ( | ) |
Clear all plugins (for testing)
Calls shutdown_all() and removes all plugins. Use with caution in production code.
| auto kcenon::monitoring::collector_registry::get_plugin | ( | std::string_view | name | ) | -> collector_plugin * |
Get a plugin by name.
| name | Plugin name |
If the plugin was registered via factory and not yet instantiated, this will trigger instantiation.
| auto kcenon::monitoring::collector_registry::get_plugin_loader_error | ( | ) | const -> std::string |
Get the last error from plugin loader.
| auto kcenon::monitoring::collector_registry::get_plugins | ( | ) | -> std::vector< collector_plugin * > |
Get all registered plugins.
Triggers instantiation of any factory-registered plugins.
| auto kcenon::monitoring::collector_registry::get_plugins_by_category | ( | plugin_category | category | ) | -> std::vector< collector_plugin * > |
Get plugins in a specific category.
| category | Plugin category filter |
Triggers instantiation of any factory-registered plugins.
| auto kcenon::monitoring::collector_registry::get_registry_stats | ( | ) | const -> std::map< std::string, size_t > |
Get registry statistics.
Available statistics:
| auto kcenon::monitoring::collector_registry::has_plugin | ( | std::string_view | name | ) | const -> bool |
Check if a plugin is registered.
| name | Plugin name |
| auto kcenon::monitoring::collector_registry::initialize_all | ( | const config_map & | config = {} | ) | -> size_t |
Initialize all registered plugins.
| config | Configuration map (optional) |
Calls initialize() on each plugin. Plugins that fail initialization remain registered but may fail collection.
|
static |
Get the singleton instance.
Referenced by main(), kcenon::monitoring::register_builtin_collectors(), CollectorRegistryIntegrationTest::SetUp(), CollectorRegistryIntegrationTest::TearDown(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

|
private |
Instantiate a plugin from factory if needed.
| name | Plugin name |
| auto kcenon::monitoring::collector_registry::load_plugin | ( | std::string_view | path | ) | -> bool |
Load a plugin from a shared library.
| path | Path to the shared library (.so/.dylib/.dll) |
This method:
If loading fails, check the loader's error message via get_plugin_loader_error().
|
delete |
|
delete |
| auto kcenon::monitoring::collector_registry::plugin_count | ( | ) | const -> size_t |
Get the number of registered plugins.
|
inline |
Register a factory function for lazy instantiation.
| T | Plugin type (must derive from collector_plugin) |
| name | Plugin name (used for lookup) |
The factory function will be called when the plugin is first accessed. This allows deferring plugin construction until needed.
Definition at line 119 of file collector_registry.h.
References factories_, and mutex_.
| auto kcenon::monitoring::collector_registry::register_plugin | ( | std::unique_ptr< collector_plugin > | plugin | ) | -> bool |
Register a plugin instance.
| plugin | Unique pointer to the plugin |
The registry takes ownership of the plugin. If a plugin with the same name already exists, registration fails. Unavailable plugins (is_available() returns false) are not registered.
| void kcenon::monitoring::collector_registry::shutdown_all | ( | ) |
Shutdown all registered plugins.
Calls shutdown() on each plugin in reverse registration order. Safe to call multiple times.
| auto kcenon::monitoring::collector_registry::unload_plugin | ( | std::string_view | name | ) | -> bool |
Unload a dynamically loaded plugin.
| name | Plugin name |
This method:
Only plugins loaded via load_plugin() can be unloaded this way.
| auto kcenon::monitoring::collector_registry::unregister_plugin | ( | std::string_view | name | ) | -> bool |
Unregister a plugin by name.
| name | Plugin name |
Calls shutdown() on the plugin before removal.
|
private |
Definition at line 263 of file collector_registry.h.
Referenced by register_factory().
|
private |
Definition at line 266 of file collector_registry.h.
|
mutableprivate |
Definition at line 269 of file collector_registry.h.
Referenced by register_factory().
|
private |
Definition at line 275 of file collector_registry.h.
|
private |
Definition at line 260 of file collector_registry.h.
|
private |
Definition at line 272 of file collector_registry.h.