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