blob: 36d027ec2203dfb2a6b34f19a3819b0326ae436a [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>
Patrick Williams6662be32024-02-22 13:35:46 -06005#include <xyz/openbmc_project/Inventory/Item/Bmc/common.hpp>
6#include <xyz/openbmc_project/Inventory/Item/common.hpp>
Jagpal Singh Gill81da1372023-12-15 17:01:03 -08007
8PHOSPHOR_LOG2_USING;
9
10namespace phosphor::health::monitor
11{
12
13using namespace phosphor::health::utils;
14
Patrick Williams84d0a882024-02-22 12:57:09 -060015auto HealthMonitor::startup() -> sdbusplus::async::task<>
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080016{
17 info("Creating Health Monitor with config size {SIZE}", "SIZE",
18 configs.size());
Patrick Williams6662be32024-02-22 13:35:46 -060019
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);
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080025
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>(
Patrick Williams84d0a882024-02-22 12:57:09 -060032 ctx.get_bus(), type, collectionConfig, bmcPaths);
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080033 }
Patrick Williams84d0a882024-02-22 12:57:09 -060034
35 co_await run();
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080036}
37
Patrick Williams84d0a882024-02-22 12:57:09 -060038auto HealthMonitor::run() -> sdbusplus::async::task<>
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080039{
40 info("Running Health Monitor");
Patrick Williams84d0a882024-02-22 12:57:09 -060041 while (!ctx.stop_requested())
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080042 {
Patrick Williams84d0a882024-02-22 12:57:09 -060043 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(5));
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080050 }
51}
52
53} // namespace phosphor::health::monitor
54
55using namespace phosphor::health::monitor;
56
57int 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");
Patrick Williams84d0a882024-02-22 12:57:09 -060065 HealthMonitor healthMonitor{ctx};
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080066 ctx.request_name(healthMonitorServiceName);
67
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080068 ctx.run();
69 return 0;
70}