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