Add process collector

This commit is contained in:
2025-09-03 14:38:10 -04:00
parent 2fa5b3e960
commit f0916d8269
6 changed files with 243 additions and 2 deletions

View File

@@ -45,6 +45,7 @@
#include <functional>
#include <initializer_list>
#include <memory>
#include <span>
#include <type_traits>
#include <vector>
@@ -231,6 +232,36 @@ bool is_valid_label_value(std::string_view value);
// when no metric objects are in use and no concurrent render() calls.
void reset_metrics_for_testing();
/**
* @brief Interface for a custom collector that can be registered with the
* metrics system.
*
* This is used for complex metric gathering, such as reading from /proc, where
* multiple metrics need to be updated from a single data source.
*/
struct Collector {
/**
* @brief Virtual destructor.
*/
virtual ~Collector() = default;
/**
* @brief Called by the metrics system to update the metrics this collector is
* responsible for.
*/
virtual void collect() = 0;
};
/**
* @brief Register a collector with the metrics system.
*
* The system will hold a shared_ptr to the collector and call its collect()
* method during each metric rendering.
*
* @param collector A shared_ptr to the collector to be registered.
*/
void register_collector(std::shared_ptr<Collector> collector);
// Note: Histograms do not support callbacks due to their multi-value nature
// (buckets + sum + count). Use static histogram metrics only.