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