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 auto HealthMonitor::startup() -> sdbusplus::async::task<>
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(ctx.get_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                 ctx.get_bus(), type, collectionConfig, bmcPaths);
27     }
28 
29     co_await run();
30 }
31 
32 auto HealthMonitor::run() -> sdbusplus::async::task<>
33 {
34     info("Running Health Monitor");
35     while (!ctx.stop_requested())
36     {
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));
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");
59     HealthMonitor healthMonitor{ctx};
60     ctx.request_name(healthMonitorServiceName);
61 
62     ctx.run();
63     return 0;
64 }
65