1 #pragma once 2 3 #include <sdbusplus/message.hpp> 4 #include <xyz/openbmc_project/Common/Threshold/server.hpp> 5 6 #include <chrono> 7 #include <limits> 8 #include <map> 9 #include <string> 10 #include <vector> 11 12 namespace phosphor::health::metric 13 { 14 15 using ThresholdIntf = 16 sdbusplus::server::xyz::openbmc_project::common::Threshold; 17 18 enum class Type 19 { 20 cpu, 21 memory, 22 storage, 23 inode, 24 unknown 25 }; 26 27 enum class SubType 28 { 29 // CPU subtypes 30 cpuKernel, 31 cpuTotal, 32 cpuUser, 33 // Memory subtypes 34 memoryAvailable, 35 memoryBufferedAndCached, 36 memoryFree, 37 memoryShared, 38 memoryTotal, 39 // Types for which subtype is not applicable 40 NA 41 }; 42 43 auto to_string(Type) -> std::string; 44 auto to_string(SubType) -> std::string; 45 46 namespace config 47 { 48 49 using namespace std::literals::chrono_literals; 50 51 struct Threshold 52 { 53 double value = defaults::value; 54 bool log = false; 55 std::string target = defaults::target; 56 57 using map_t = 58 std::map<std::tuple<ThresholdIntf::Type, ThresholdIntf::Bound>, 59 Threshold>; 60 61 struct defaults 62 { 63 static constexpr auto value = std::numeric_limits<double>::quiet_NaN(); 64 static constexpr auto target = ""; 65 }; 66 }; 67 68 struct HealthMetric 69 { 70 /** @brief The name of the metric. */ 71 std::string name = "unnamed"; 72 /** @brief The metric subtype. */ 73 SubType subType = SubType::NA; 74 /** @brief The window size for the metric. */ 75 size_t windowSize = defaults::windowSize; 76 /** @brief The hysteresis for the metric */ 77 double hysteresis = defaults::hysteresis; 78 /** @brief The threshold configs for the metric. */ 79 Threshold::map_t thresholds{}; 80 /** @brief The path for filesystem metric */ 81 std::string path = defaults::path; 82 83 using map_t = std::map<Type, std::vector<HealthMetric>>; 84 85 struct defaults 86 { 87 static constexpr auto windowSize = 120; 88 static constexpr auto path = ""; 89 static constexpr auto hysteresis = 1.0; 90 }; 91 }; 92 93 /** @brief Get the health metric configs. */ 94 auto getHealthMetricConfigs() -> HealthMetric::map_t; 95 96 } // namespace config 97 } // namespace phosphor::health::metric 98