| Jagpal Singh Gill | 23f091e | 2023-12-10 15:23:19 -0800 | [diff] [blame] | 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>; | 
| Jagpal Singh Gill | 9758280 | 2024-02-27 13:59:11 -0800 | [diff] [blame] | 28 | using MType = phosphor::health::metric::Type; | 
| Jagpal Singh Gill | 23f091e | 2023-12-10 15:23:19 -0800 | [diff] [blame] | 29 |  | 
|  | 30 | struct MValue | 
|  | 31 | { | 
| Jagpal Singh Gill | 6a3884a | 2024-02-24 18:08:23 -0800 | [diff] [blame] | 32 | /** @brief Current value of metric */ | 
|  | 33 | double current; | 
|  | 34 | /** @brief Total value of metric */ | 
|  | 35 | double total; | 
| Jagpal Singh Gill | 23f091e | 2023-12-10 15:23:19 -0800 | [diff] [blame] | 36 | }; | 
|  | 37 |  | 
|  | 38 | class HealthMetric : public MetricIntf | 
|  | 39 | { | 
|  | 40 | public: | 
|  | 41 | HealthMetric() = delete; | 
|  | 42 | HealthMetric(const HealthMetric&) = delete; | 
|  | 43 | HealthMetric(HealthMetric&&) = delete; | 
|  | 44 | virtual ~HealthMetric() = default; | 
|  | 45 |  | 
| Jagpal Singh Gill | 9758280 | 2024-02-27 13:59:11 -0800 | [diff] [blame] | 46 | HealthMetric(sdbusplus::bus_t& bus, MType type, | 
| Jagpal Singh Gill | 23f091e | 2023-12-10 15:23:19 -0800 | [diff] [blame] | 47 | const config::HealthMetric& config, const paths_t& bmcPaths) : | 
| Jagpal Singh Gill | 9758280 | 2024-02-27 13:59:11 -0800 | [diff] [blame] | 48 | MetricIntf(bus, getPath(type, config.name, config.subType).c_str(), | 
|  | 49 | action::defer_emit), | 
| Jagpal Singh Gill | 23f091e | 2023-12-10 15:23:19 -0800 | [diff] [blame] | 50 | bus(bus), type(type), config(config) | 
|  | 51 | { | 
|  | 52 | create(bmcPaths); | 
|  | 53 | this->emit_object_added(); | 
|  | 54 | } | 
|  | 55 |  | 
|  | 56 | /** @brief Update the health metric with the given value */ | 
|  | 57 | void update(MValue value); | 
|  | 58 |  | 
|  | 59 | private: | 
|  | 60 | /** @brief Create a new health metric object */ | 
|  | 61 | void create(const paths_t& bmcPaths); | 
|  | 62 | /** @brief Init properties for the health metric object */ | 
|  | 63 | void initProperties(); | 
|  | 64 | /** @brief Check specified threshold for the given value */ | 
|  | 65 | void checkThreshold(ThresholdIntf::Type type, ThresholdIntf::Bound bound, | 
| Jagpal Singh Gill | 6a3884a | 2024-02-24 18:08:23 -0800 | [diff] [blame] | 66 | MValue value); | 
| Jagpal Singh Gill | 23f091e | 2023-12-10 15:23:19 -0800 | [diff] [blame] | 67 | /** @brief Check all thresholds for the given value */ | 
| Jagpal Singh Gill | 6a3884a | 2024-02-24 18:08:23 -0800 | [diff] [blame] | 68 | void checkThresholds(MValue value); | 
| Jagpal Singh Gill | 9758280 | 2024-02-27 13:59:11 -0800 | [diff] [blame] | 69 | /** @brief Get the object path for the given type, name and subtype */ | 
|  | 70 | auto getPath(phosphor::health::metric::Type type, std::string name, | 
|  | 71 | SubType subType) -> std::string; | 
| Jagpal Singh Gill | 23f091e | 2023-12-10 15:23:19 -0800 | [diff] [blame] | 72 | /** @brief D-Bus bus connection */ | 
| Patrick Williams | cfd889f | 2024-02-10 02:39:17 -0600 | [diff] [blame] | 73 | sdbusplus::bus_t& bus; | 
| Jagpal Singh Gill | 23f091e | 2023-12-10 15:23:19 -0800 | [diff] [blame] | 74 | /** @brief Metric type */ | 
| Jagpal Singh Gill | 9758280 | 2024-02-27 13:59:11 -0800 | [diff] [blame] | 75 | MType type; | 
| Jagpal Singh Gill | 23f091e | 2023-12-10 15:23:19 -0800 | [diff] [blame] | 76 | /** @brief Metric configuration */ | 
|  | 77 | const config::HealthMetric config; | 
|  | 78 | /** @brief Window for metric history */ | 
|  | 79 | std::deque<double> history; | 
|  | 80 | }; | 
|  | 81 |  | 
|  | 82 | } // namespace phosphor::health::metric |