#include "health_monitor.hpp" #include #include PHOSPHOR_LOG2_USING; namespace phosphor::health::monitor { using namespace phosphor::health::utils; auto HealthMonitor::startup() -> sdbusplus::async::task<> { info("Creating Health Monitor with config size {SIZE}", "SIZE", configs.size()); constexpr auto BMCInventoryItem = "xyz.openbmc_project.Inventory.Item.Bmc"; auto bmcPaths = findPaths(ctx.get_bus(), BMCInventoryItem); for (auto& [type, collectionConfig] : configs) { info("Creating Health Metric Collection for {TYPE}", "TYPE", std::to_underlying(type)); collections[type] = std::make_unique( ctx.get_bus(), type, collectionConfig, bmcPaths); } co_await run(); } auto HealthMonitor::run() -> sdbusplus::async::task<> { info("Running Health Monitor"); while (!ctx.stop_requested()) { for (auto& [type, collection] : collections) { debug("Reading Health Metric Collection for {TYPE}", "TYPE", std::to_underlying(type)); collection->read(); } co_await sdbusplus::async::sleep_for(ctx, std::chrono::seconds(5)); } } } // namespace phosphor::health::monitor using namespace phosphor::health::monitor; int main() { constexpr auto path = MetricIntf::ValueIntf::Value::namespace_path::value; sdbusplus::async::context ctx; sdbusplus::server::manager_t manager{ctx, path}; constexpr auto healthMonitorServiceName = "xyz.openbmc_project.HealthMon"; info("Creating health monitor"); HealthMonitor healthMonitor{ctx}; ctx.request_name(healthMonitorServiceName); ctx.run(); return 0; }