add health_metric_collection implementation
Add the interface and implementation for health_metric_collection which
encapsulates various health_metrics.
This change is in relation to following design and D-Bus interface
update -
https://gerrit.openbmc.org/c/openbmc/docs/+/64917
https://gerrit.openbmc.org/c/openbmc/phosphor-dbus-interfaces/+/64914
Add test_health_metric_collection gtest for unit testing.
Change-Id: Ia0b9fbc6bec4850735c7eb74dcd5c40fc47c568c
Signed-off-by: Jagpal Singh Gill <paligill@gmail.com>
diff --git a/health_metric_collection.hpp b/health_metric_collection.hpp
new file mode 100644
index 0000000..51a92e3
--- /dev/null
+++ b/health_metric_collection.hpp
@@ -0,0 +1,53 @@
+#pragma once
+
+#include "health_metric.hpp"
+
+namespace phosphor::health::metric::collection
+{
+namespace ConfigIntf = phosphor::health::metric::config;
+namespace MetricIntf = phosphor::health::metric;
+
+using configs_t = std::vector<ConfigIntf::HealthMetric>;
+
+class HealthMetricCollection
+{
+ public:
+ HealthMetricCollection(sdbusplus::bus_t& bus, MetricIntf::Type type,
+ const configs_t& configs,
+ MetricIntf::paths_t& bmcPaths) :
+ bus(bus),
+ type(type), configs(configs)
+ {
+ create(bmcPaths);
+ }
+
+ /** @brief Read the health metric collection from the system */
+ void read();
+
+ private:
+ using map_t = std::unordered_map<MetricIntf::SubType,
+ std::unique_ptr<MetricIntf::HealthMetric>>;
+ using time_map_t = std::unordered_map<MetricIntf::SubType, uint64_t>;
+ /** @brief Create a new health metric collection object */
+ void create(const MetricIntf::paths_t& bmcPaths);
+ /** @brief Read the CPU */
+ auto readCPU() -> bool;
+ /** @brief Read the memory */
+ auto readMemory() -> bool;
+ /** @brief Read the storage */
+ auto readStorage() -> bool;
+ /** @brief D-Bus bus connection */
+ sdbusplus::bus_t& bus;
+ /** @brief Metric type */
+ MetricIntf::Type type;
+ /** @brief Health metric configs */
+ const configs_t& configs;
+ /** @brief Map of health metrics by subtype */
+ map_t metrics;
+ /** @brief Map for active time by subtype */
+ time_map_t preActiveTime;
+ /** @brief Map for total time by subtype */
+ time_map_t preTotalTime;
+};
+
+} // namespace phosphor::health::metric::collection