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 threshold configs for the metric. */ 77 Threshold::map_t thresholds{}; 78 /** @brief The path for filesystem metric */ 79 std::string path = defaults::path; 80 81 using map_t = std::map<Type, std::vector<HealthMetric>>; 82 83 struct defaults 84 { 85 static constexpr auto windowSize = 1; 86 static constexpr auto path = ""; 87 }; 88 }; 89 90 /** @brief Get the health metric configs. */ 91 auto getHealthMetricConfigs() -> HealthMetric::map_t; 92 93 } // namespace config 94 } // namespace phosphor::health::metric 95