#include <chrono>
#include <iostream>
#include <thread>
std::cout << "=== Plugin-based Metric Collector Example ===" << std::endl;
auto collector = std::make_unique<plugin_metric_collector>(config);
auto sys_collector = std::make_unique<system_resource_collector>();
if (sys_collector->initialize({})) {
std::cout << "System resource collector initialized" << std::endl;
collector->register_plugin(std::move(sys_collector));
}
auto thread_collector = std::make_unique<thread_system_collector>();
if (thread_collector->initialize({})) {
std::cout << "Thread system collector initialized" << std::endl;
collector->register_plugin(std::move(thread_collector));
}
auto logger_collector = std::make_unique<logger_system_collector>();
if (logger_collector->initialize({})) {
std::cout << "Logger system collector initialized" << std::endl;
collector->register_plugin(std::move(logger_collector));
}
std::cout << "\nRegistered plugins:" << std::endl;
for (const auto& plugin_name : collector->get_registered_plugins()) {
std::cout << " - " << plugin_name << std::endl;
}
if (collector->start()) {
std::cout << "\nCollection started successfully" << std::endl;
} else {
std::cerr << "Failed to start collection" << std::endl;
return 1;
}
std::cout << "\nCollecting metrics for 5 seconds..." << std::endl;
for (int i = 0; i < 5; ++i) {
std::this_thread::sleep_for(std::chrono::seconds(1));
auto metrics = collector->force_collect();
std::cout << "Collected " << metrics.size() << " metrics" << std::endl;
for (
const auto&
metric : metrics) {
if (i == 0) {
}
}
}
auto cached = collector->get_cached_metrics();
std::cout << "\nTotal cached metrics: " << cached.size() << std::endl;
collector->stop();
std::cout << "Collection stopped" << std::endl;
return 0;
}
Metric collector for logger_system log statistics.
Plugin-based metric collector with dynamic discovery and registration.
Basic metric structure for interface compatibility.
std::variant< double, int64_t, std::string > value
std::chrono::milliseconds collection_interval
System resource collector for CPU, memory, and disk metrics.
Metric collector for thread_system pool and queue statistics.