Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
test_collector_registry_integration.cpp
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#include <gtest/gtest.h>
6
9
10using namespace kcenon::monitoring;
11
12class CollectorRegistryIntegrationTest : public ::testing::Test {
13protected:
14 void SetUp() override {
15 // Clean registry before each test
16 auto& registry = collector_registry::instance();
17 registry.clear();
18 }
19
20 void TearDown() override {
21 // Clean up after test
22 auto& registry = collector_registry::instance();
23 registry.clear();
24 }
25};
26
27// Test that all builtin collectors are registered with the registry
28TEST_F(CollectorRegistryIntegrationTest, BuiltinCollectorsRegisteredWithRegistry) {
29 auto& registry = collector_registry::instance();
30
31 // Register all builtin collectors
33 EXPECT_TRUE(success);
34
35 // Check that we have 9 plugin-based collectors registered
36 // (battery, uptime, interrupt, network_metrics, platform_metrics,
37 // process_metrics, security, smart, vm)
38 auto total_plugins = registry.plugin_count();
39 EXPECT_EQ(total_plugins, 9);
40}
41
42// Test that get_plugins returns all registered collectors
43TEST_F(CollectorRegistryIntegrationTest, GetPluginsReturnsAllCollectors) {
44 auto& registry = collector_registry::instance();
45
46 // Register builtin collectors
48
49 // Try to get a specific plugin first (safer)
50 auto* battery = registry.get_plugin("battery_collector");
51
52 // If battery collector is available on this platform
53 if (battery != nullptr) {
54 // Check that it has a valid name (the actual implementation uses "battery")
55 EXPECT_FALSE(std::string(battery->name()).empty());
56 }
57
58 // Check plugin count
59 auto total_plugins = registry.plugin_count();
60 EXPECT_EQ(total_plugins, 9);
61}
62
63// Test registry statistics
65 auto& registry = collector_registry::instance();
66
67 // Register builtin collectors
69
70 // Get statistics (without triggering full instantiation)
71 auto stats = registry.get_registry_stats();
72
73 // Should have total_plugins stat
74 EXPECT_TRUE(stats.find("total_plugins") != stats.end());
75}
76
77// Test that specific collectors can be retrieved
79 auto& registry = collector_registry::instance();
80
81 // Register builtin collectors
83
84 // Try to get battery_collector
85 auto* battery = registry.get_plugin("battery_collector");
86
87 // Should either be valid or null (if not available on platform)
88 if (battery != nullptr) {
89 // Check that it has a valid name
90 EXPECT_FALSE(std::string(battery->name()).empty());
91 }
92}
93
94// Test initialization of all plugins
96 auto& registry = collector_registry::instance();
97
98 // Register builtin collectors
100
101 // Get a specific plugin
102 auto* uptime = registry.get_plugin("uptime_collector");
103
104 if (uptime != nullptr) {
105 // Initialize this specific plugin
106 config_map config;
107 bool init_result = uptime->initialize(config);
108 EXPECT_TRUE(init_result);
109 }
110}
111
112// Test that has_plugin works correctly
114 auto& registry = collector_registry::instance();
115
116 // Register builtin collectors
118
119 // Should have battery_collector registered
120 EXPECT_TRUE(registry.has_plugin("battery_collector"));
121
122 // Should have uptime_collector registered
123 EXPECT_TRUE(registry.has_plugin("uptime_collector"));
124
125 // Should not have a non-existent collector
126 EXPECT_FALSE(registry.has_plugin("non_existent_collector"));
127}
Registration of built-in metric collectors with the registry.
static auto instance() -> collector_registry &
Get the singleton instance.
Registry for managing collector plugin lifecycle.
std::unordered_map< std::string, std::string > config_map
Type alias for configuration map.
bool register_builtin_collectors()
Register all built-in collectors with the collector_registry.
TEST_F(CollectorRegistryIntegrationTest, BuiltinCollectorsRegisteredWithRegistry)