Jagpal Singh Gill | 7e11ab0 | 2023-12-08 11:41:41 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Williams | 67b8ebe | 2024-02-23 20:40:52 -0600 | [diff] [blame] | 3 | #include <sdbusplus/message.hpp> |
Jagpal Singh Gill | 7e11ab0 | 2023-12-08 11:41:41 -0800 | [diff] [blame] | 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, |
Jagpal Singh Gill | 9758280 | 2024-02-27 13:59:11 -0800 | [diff] [blame] | 39 | // Types for which subtype is not applicable |
Jagpal Singh Gill | 7e11ab0 | 2023-12-08 11:41:41 -0800 | [diff] [blame] | 40 | NA |
| 41 | }; |
| 42 | |
Patrick Williams | 67b8ebe | 2024-02-23 20:40:52 -0600 | [diff] [blame] | 43 | auto to_string(Type) -> std::string; |
| 44 | auto to_string(SubType) -> std::string; |
| 45 | |
Jagpal Singh Gill | 7e11ab0 | 2023-12-08 11:41:41 -0800 | [diff] [blame] | 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; |
Jagpal Singh Gill | 7e11ab0 | 2023-12-08 11:41:41 -0800 | [diff] [blame] | 74 | /** @brief The window size for the metric. */ |
| 75 | size_t windowSize = defaults::windowSize; |
Jagpal Singh Gill | a102762 | 2024-03-05 17:57:33 -0800 | [diff] [blame] | 76 | /** @brief The hysteresis for the metric */ |
| 77 | double hysteresis = defaults::hysteresis; |
Jagpal Singh Gill | 7e11ab0 | 2023-12-08 11:41:41 -0800 | [diff] [blame] | 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 | { |
Jagpal Singh Gill | 2188317 | 2024-03-06 11:37:26 -0800 | [diff] [blame] | 87 | static constexpr auto windowSize = 120; |
Jagpal Singh Gill | 7e11ab0 | 2023-12-08 11:41:41 -0800 | [diff] [blame] | 88 | static constexpr auto path = ""; |
Jagpal Singh Gill | a102762 | 2024-03-05 17:57:33 -0800 | [diff] [blame] | 89 | static constexpr auto hysteresis = 1.0; |
Jagpal Singh Gill | 7e11ab0 | 2023-12-08 11:41:41 -0800 | [diff] [blame] | 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 |