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 | |
| 13 | void HealthMonitor::create() |
| 14 | { |
| 15 | info("Creating Health Monitor with config size {SIZE}", "SIZE", |
| 16 | configs.size()); |
| 17 | constexpr auto BMCInventoryItem = "xyz.openbmc_project.Inventory.Item.Bmc"; |
| 18 | auto bmcPaths = findPaths(bus, BMCInventoryItem); |
| 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>( |
| 26 | bus, type, collectionConfig, bmcPaths); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | void HealthMonitor::run() |
| 31 | { |
| 32 | info("Running Health Monitor"); |
| 33 | for (auto& [type, collection] : collections) |
| 34 | { |
| 35 | debug("Reading Health Metric Collection for {TYPE}", "TYPE", |
| 36 | std::to_underlying(type)); |
| 37 | collection->read(); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | } // namespace phosphor::health::monitor |
| 42 | |
| 43 | using namespace phosphor::health::monitor; |
| 44 | |
| 45 | int main() |
| 46 | { |
| 47 | constexpr auto path = MetricIntf::ValueIntf::Value::namespace_path::value; |
| 48 | sdbusplus::async::context ctx; |
| 49 | sdbusplus::server::manager_t manager{ctx, path}; |
| 50 | constexpr auto healthMonitorServiceName = "xyz.openbmc_project.HealthMon"; |
| 51 | |
| 52 | info("Creating health monitor"); |
| 53 | HealthMonitor healthMonitor{ctx.get_bus()}; |
| 54 | ctx.request_name(healthMonitorServiceName); |
| 55 | |
| 56 | ctx.spawn([&]() -> sdbusplus::async::task<> { |
| 57 | while (!ctx.stop_requested()) |
| 58 | { |
| 59 | healthMonitor.run(); |
| 60 | co_await sdbusplus::async::sleep_for(ctx, std::chrono::seconds(5)); |
| 61 | } |
| 62 | }()); |
| 63 | |
| 64 | ctx.run(); |
| 65 | return 0; |
| 66 | } |