add health_metric_config implementation
Add the health_metric_config interface and implementation for
phosphor-health-monitor. This interface will be used in the
re-write of phosphor-health-monitor.
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
gtest added for UT.
Change-Id: Ic40faafbb57597023cc70036428d46ee69a895a2
Signed-off-by: Jagpal Singh Gill <paligill@gmail.com>
diff --git a/health_metric_config.hpp b/health_metric_config.hpp
new file mode 100644
index 0000000..2b0a578
--- /dev/null
+++ b/health_metric_config.hpp
@@ -0,0 +1,94 @@
+#pragma once
+
+#include <xyz/openbmc_project/Common/Threshold/server.hpp>
+
+#include <chrono>
+#include <limits>
+#include <map>
+#include <string>
+#include <vector>
+
+namespace phosphor::health::metric
+{
+
+using ThresholdIntf =
+ sdbusplus::server::xyz::openbmc_project::common::Threshold;
+
+enum class Type
+{
+ cpu,
+ memory,
+ storage,
+ inode,
+ unknown
+};
+
+enum class SubType
+{
+ // CPU subtypes
+ cpuKernel,
+ cpuTotal,
+ cpuUser,
+ // Memory subtypes
+ memoryAvailable,
+ memoryBufferedAndCached,
+ memoryFree,
+ memoryShared,
+ memoryTotal,
+ // Storage subtypes
+ storageReadWrite,
+ NA
+};
+
+namespace config
+{
+
+using namespace std::literals::chrono_literals;
+
+struct Threshold
+{
+ double value = defaults::value;
+ bool log = false;
+ std::string target = defaults::target;
+
+ using map_t =
+ std::map<std::tuple<ThresholdIntf::Type, ThresholdIntf::Bound>,
+ Threshold>;
+
+ struct defaults
+ {
+ static constexpr auto value = std::numeric_limits<double>::quiet_NaN();
+ static constexpr auto target = "";
+ };
+};
+
+struct HealthMetric
+{
+ /** @brief The name of the metric. */
+ std::string name = "unnamed";
+ /** @brief The metric subtype. */
+ SubType subType = SubType::NA;
+ /** @brief The collection frequency for the metric. */
+ std::chrono::seconds collectionFreq = defaults::frequency;
+ /** @brief The window size for the metric. */
+ size_t windowSize = defaults::windowSize;
+ /** @brief The threshold configs for the metric. */
+ Threshold::map_t thresholds{};
+ /** @brief The path for filesystem metric */
+ std::string path = defaults::path;
+
+ using map_t = std::map<Type, std::vector<HealthMetric>>;
+
+ struct defaults
+ {
+ static constexpr auto frequency = 1s;
+ static constexpr auto windowSize = 1;
+ static constexpr auto path = "";
+ };
+};
+
+/** @brief Get the health metric configs. */
+auto getHealthMetricConfigs() -> HealthMetric::map_t;
+
+} // namespace config
+} // namespace phosphor::health::metric