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",
29              std::to_underlying(type));
30         collections[type] =
31             std::make_unique<CollectionIntf::HealthMetricCollection>(
32                 ctx.get_bus(), type, collectionConfig, bmcPaths);
33     }
34 
35     co_await run();
36 }
37 
38 auto HealthMonitor::run() -> sdbusplus::async::task<>
39 {
40     info("Running Health Monitor");
41     while (!ctx.stop_requested())
42     {
43         for (auto& [type, collection] : collections)
44         {
45             debug("Reading Health Metric Collection for {TYPE}", "TYPE",
46                   std::to_underlying(type));
47             collection->read();
48         }
49         co_await sdbusplus::async::sleep_for(ctx, std::chrono::seconds(1));
50     }
51 }
52 
53 } // namespace phosphor::health::monitor
54 
55 using namespace phosphor::health::monitor;
56 
57 int main()
58 {
59     constexpr auto path = MetricIntf::ValueIntf::Value::namespace_path::value;
60     sdbusplus::async::context ctx;
61     sdbusplus::server::manager_t manager{ctx, path};
62     constexpr auto healthMonitorServiceName = "xyz.openbmc_project.HealthMon";
63 
64     info("Creating health monitor");
65     HealthMonitor healthMonitor{ctx};
66     ctx.request_name(healthMonitorServiceName);
67 
68     ctx.run();
69     return 0;
70 }
71