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