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