1 #pragma once 2 3 #include "health_metric_config.hpp" 4 #include "health_utils.hpp" 5 6 #include <xyz/openbmc_project/Association/Definitions/server.hpp> 7 #include <xyz/openbmc_project/Inventory/Item/Bmc/server.hpp> 8 #include <xyz/openbmc_project/Metric/Value/server.hpp> 9 10 #include <deque> 11 #include <tuple> 12 13 namespace phosphor::health::metric 14 { 15 16 using phosphor::health::utils::paths_t; 17 using phosphor::health::utils::startUnit; 18 using AssociationIntf = 19 sdbusplus::xyz::openbmc_project::Association::server::Definitions; 20 using ValueIntf = sdbusplus::xyz::openbmc_project::Metric::server::Value; 21 using PathIntf = 22 sdbusplus::common::xyz::openbmc_project::metric::Value::namespace_path; 23 static constexpr auto BmcPath = 24 sdbusplus::common::xyz::openbmc_project::metric::Value::bmc; 25 using BmcIntf = sdbusplus::xyz::openbmc_project::Inventory::Item::server::Bmc; 26 using MetricIntf = 27 sdbusplus::server::object_t<ValueIntf, ThresholdIntf, AssociationIntf>; 28 29 struct MValue 30 { 31 /** @brief Value for end user consumption */ 32 double user; 33 /** @brief Value for threshold monitor */ 34 double monitor; 35 }; 36 37 class HealthMetric : public MetricIntf 38 { 39 public: 40 HealthMetric() = delete; 41 HealthMetric(const HealthMetric&) = delete; 42 HealthMetric(HealthMetric&&) = delete; 43 virtual ~HealthMetric() = default; 44 45 HealthMetric(sdbusplus::bus::bus& bus, phosphor::health::metric::Type type, 46 const config::HealthMetric& config, const paths_t& bmcPaths) : 47 MetricIntf(bus, getPath(config.subType).c_str(), action::defer_emit), 48 bus(bus), type(type), config(config) 49 { 50 create(bmcPaths); 51 this->emit_object_added(); 52 } 53 54 /** @brief Update the health metric with the given value */ 55 void update(MValue value); 56 57 private: 58 /** @brief Create a new health metric object */ 59 void create(const paths_t& bmcPaths); 60 /** @brief Init properties for the health metric object */ 61 void initProperties(); 62 /** @brief Check specified threshold for the given value */ 63 void checkThreshold(ThresholdIntf::Type type, ThresholdIntf::Bound bound, 64 double value); 65 /** @brief Check all thresholds for the given value */ 66 void checkThresholds(double value); 67 /** @brief Get the object path for the given subtype */ 68 auto getPath(SubType subType) -> std::string; 69 /** @brief D-Bus bus connection */ 70 sdbusplus::bus::bus& bus; 71 /** @brief Metric type */ 72 phosphor::health::metric::Type type; 73 /** @brief Metric configuration */ 74 const config::HealthMetric config; 75 /** @brief Window for metric history */ 76 std::deque<double> history; 77 }; 78 79 } // namespace phosphor::health::metric 80