blob: 772bdf9a38368b628270dcdd372664bc64e396a4 [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 {
Patrick Williams67b8ebe2024-02-23 20:40:52 -060028 info("Creating Health Metric Collection for {TYPE}", "TYPE", type);
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080029 collections[type] =
30 std::make_unique<CollectionIntf::HealthMetricCollection>(
Patrick Williams84d0a882024-02-22 12:57:09 -060031 ctx.get_bus(), type, collectionConfig, bmcPaths);
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080032 }
Patrick Williams84d0a882024-02-22 12:57:09 -060033
34 co_await run();
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080035}
36
Patrick Williams84d0a882024-02-22 12:57:09 -060037auto HealthMonitor::run() -> sdbusplus::async::task<>
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080038{
39 info("Running Health Monitor");
Patrick Williams84d0a882024-02-22 12:57:09 -060040 while (!ctx.stop_requested())
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080041 {
Patrick Williams84d0a882024-02-22 12:57:09 -060042 for (auto& [type, collection] : collections)
43 {
Patrick Williams67b8ebe2024-02-23 20:40:52 -060044 debug("Reading Health Metric Collection for {TYPE}", "TYPE", type);
Patrick Williams84d0a882024-02-22 12:57:09 -060045 collection->read();
46 }
Jagpal Singh Gill1a290722024-02-24 23:40:51 -080047 co_await sdbusplus::async::sleep_for(ctx, std::chrono::seconds(1));
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080048 }
49}
50
51} // namespace phosphor::health::monitor
52
53using namespace phosphor::health::monitor;
54
55int main()
56{
57 constexpr auto path = MetricIntf::ValueIntf::Value::namespace_path::value;
58 sdbusplus::async::context ctx;
59 sdbusplus::server::manager_t manager{ctx, path};
60 constexpr auto healthMonitorServiceName = "xyz.openbmc_project.HealthMon";
61
62 info("Creating health monitor");
Patrick Williams84d0a882024-02-22 12:57:09 -060063 HealthMonitor healthMonitor{ctx};
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080064 ctx.request_name(healthMonitorServiceName);
65
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080066 ctx.run();
67 return 0;
68}