blob: b839ae74c81d8c200c1118d477c7cd24b0fb2ffc [file] [log] [blame]
Jagpal Singh Gill81da1372023-12-15 17:01:03 -08001#include "health_monitor.hpp"
2
3#include <phosphor-logging/lg2.hpp>
4#include <sdbusplus/async.hpp>
5
6PHOSPHOR_LOG2_USING;
7
8namespace phosphor::health::monitor
9{
10
11using namespace phosphor::health::utils;
12
13void HealthMonitor::create()
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(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 bus, type, collectionConfig, bmcPaths);
27 }
28}
29
30void HealthMonitor::run()
31{
32 info("Running Health Monitor");
33 for (auto& [type, collection] : collections)
34 {
35 debug("Reading Health Metric Collection for {TYPE}", "TYPE",
36 std::to_underlying(type));
37 collection->read();
38 }
39}
40
41} // namespace phosphor::health::monitor
42
43using namespace phosphor::health::monitor;
44
45int main()
46{
47 constexpr auto path = MetricIntf::ValueIntf::Value::namespace_path::value;
48 sdbusplus::async::context ctx;
49 sdbusplus::server::manager_t manager{ctx, path};
50 constexpr auto healthMonitorServiceName = "xyz.openbmc_project.HealthMon";
51
52 info("Creating health monitor");
53 HealthMonitor healthMonitor{ctx.get_bus()};
54 ctx.request_name(healthMonitorServiceName);
55
56 ctx.spawn([&]() -> sdbusplus::async::task<> {
57 while (!ctx.stop_requested())
58 {
59 healthMonitor.run();
60 co_await sdbusplus::async::sleep_for(ctx, std::chrono::seconds(5));
61 }
62 }());
63
64 ctx.run();
65 return 0;
66}