blob: 01f6836fa36e6ce75eebe86684fe5dc14d559997 [file] [log] [blame]
Jagpal Singh Gill23f091e2023-12-10 15:23:19 -08001#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
13namespace phosphor::health::metric
14{
15
16using phosphor::health::utils::paths_t;
17using phosphor::health::utils::startUnit;
18using AssociationIntf =
19 sdbusplus::xyz::openbmc_project::Association::server::Definitions;
20using ValueIntf = sdbusplus::xyz::openbmc_project::Metric::server::Value;
21using PathIntf =
22 sdbusplus::common::xyz::openbmc_project::metric::Value::namespace_path;
23static constexpr auto BmcPath =
24 sdbusplus::common::xyz::openbmc_project::metric::Value::bmc;
25using BmcIntf = sdbusplus::xyz::openbmc_project::Inventory::Item::server::Bmc;
26using MetricIntf =
27 sdbusplus::server::object_t<ValueIntf, ThresholdIntf, AssociationIntf>;
28
29struct MValue
30{
31 /** @brief Value for end user consumption */
32 double user;
33 /** @brief Value for threshold monitor */
34 double monitor;
35};
36
37class HealthMetric : public MetricIntf
38{
39 public:
40 HealthMetric() = delete;
41 HealthMetric(const HealthMetric&) = delete;
42 HealthMetric(HealthMetric&&) = delete;
43 virtual ~HealthMetric() = default;
44
Patrick Williamscfd889f2024-02-10 02:39:17 -060045 HealthMetric(sdbusplus::bus_t& bus, phosphor::health::metric::Type type,
Jagpal Singh Gill23f091e2023-12-10 15:23:19 -080046 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 */
Patrick Williamscfd889f2024-02-10 02:39:17 -060070 sdbusplus::bus_t& bus;
Jagpal Singh Gill23f091e2023-12-10 15:23:19 -080071 /** @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