Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 1 | #include "health_monitor.hpp" |
| 2 | |
| 3 | #include <phosphor-logging/lg2.hpp> |
| 4 | #include <sdbusplus/async.hpp> |
Patrick Williams | 6662be3 | 2024-02-22 13:35:46 -0600 | [diff] [blame] | 5 | #include <xyz/openbmc_project/Inventory/Item/Bmc/common.hpp> |
| 6 | #include <xyz/openbmc_project/Inventory/Item/common.hpp> |
Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 7 | |
| 8 | PHOSPHOR_LOG2_USING; |
| 9 | |
| 10 | namespace phosphor::health::monitor |
| 11 | { |
| 12 | |
| 13 | using namespace phosphor::health::utils; |
| 14 | |
Patrick Williams | 84d0a88 | 2024-02-22 12:57:09 -0600 | [diff] [blame] | 15 | auto HealthMonitor::startup() -> sdbusplus::async::task<> |
Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 16 | { |
| 17 | info("Creating Health Monitor with config size {SIZE}", "SIZE", |
| 18 | configs.size()); |
Patrick Williams | 6662be3 | 2024-02-22 13:35:46 -0600 | [diff] [blame] | 19 | |
| 20 | static constexpr auto bmcIntf = sdbusplus::common::xyz::openbmc_project:: |
| 21 | inventory::item::Bmc::interface; |
| 22 | static constexpr auto invPath = sdbusplus::common::xyz::openbmc_project:: |
| 23 | inventory::Item::namespace_path; |
| 24 | auto bmcPaths = co_await findPaths(ctx, bmcIntf, invPath); |
Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 25 | |
| 26 | for (auto& [type, collectionConfig] : configs) |
| 27 | { |
| 28 | info("Creating Health Metric Collection for {TYPE}", "TYPE", |
| 29 | std::to_underlying(type)); |
| 30 | collections[type] = |
| 31 | std::make_unique<CollectionIntf::HealthMetricCollection>( |
Patrick Williams | 84d0a88 | 2024-02-22 12:57:09 -0600 | [diff] [blame] | 32 | ctx.get_bus(), type, collectionConfig, bmcPaths); |
Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 33 | } |
Patrick Williams | 84d0a88 | 2024-02-22 12:57:09 -0600 | [diff] [blame] | 34 | |
| 35 | co_await run(); |
Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 36 | } |
| 37 | |
Patrick Williams | 84d0a88 | 2024-02-22 12:57:09 -0600 | [diff] [blame] | 38 | auto HealthMonitor::run() -> sdbusplus::async::task<> |
Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 39 | { |
| 40 | info("Running Health Monitor"); |
Patrick Williams | 84d0a88 | 2024-02-22 12:57:09 -0600 | [diff] [blame] | 41 | while (!ctx.stop_requested()) |
Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 42 | { |
Patrick Williams | 84d0a88 | 2024-02-22 12:57:09 -0600 | [diff] [blame] | 43 | for (auto& [type, collection] : collections) |
| 44 | { |
| 45 | debug("Reading Health Metric Collection for {TYPE}", "TYPE", |
| 46 | std::to_underlying(type)); |
| 47 | collection->read(); |
| 48 | } |
| 49 | co_await sdbusplus::async::sleep_for(ctx, std::chrono::seconds(5)); |
Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
| 53 | } // namespace phosphor::health::monitor |
| 54 | |
| 55 | using namespace phosphor::health::monitor; |
| 56 | |
| 57 | int main() |
| 58 | { |
| 59 | constexpr auto path = MetricIntf::ValueIntf::Value::namespace_path::value; |
| 60 | sdbusplus::async::context ctx; |
| 61 | sdbusplus::server::manager_t manager{ctx, path}; |
| 62 | constexpr auto healthMonitorServiceName = "xyz.openbmc_project.HealthMon"; |
| 63 | |
| 64 | info("Creating health monitor"); |
Patrick Williams | 84d0a88 | 2024-02-22 12:57:09 -0600 | [diff] [blame] | 65 | HealthMonitor healthMonitor{ctx}; |
Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 66 | ctx.request_name(healthMonitorServiceName); |
| 67 | |
Jagpal Singh Gill | 81da137 | 2023-12-15 17:01:03 -0800 | [diff] [blame] | 68 | ctx.run(); |
| 69 | return 0; |
| 70 | } |