blob: de8b723b03c184636d8639459fea83aec714be94 [file] [log] [blame]
Jagpal Singh Gillea100c92024-03-03 18:43:53 -08001#include "config.h"
2
Jagpal Singh Gill81da1372023-12-15 17:01:03 -08003#include "health_monitor.hpp"
4
5#include <phosphor-logging/lg2.hpp>
6#include <sdbusplus/async.hpp>
Patrick Williams6662be32024-02-22 13:35:46 -06007#include <xyz/openbmc_project/Inventory/Item/Bmc/common.hpp>
8#include <xyz/openbmc_project/Inventory/Item/common.hpp>
Jagpal Singh Gill81da1372023-12-15 17:01:03 -08009
10PHOSPHOR_LOG2_USING;
11
12namespace phosphor::health::monitor
13{
14
15using namespace phosphor::health::utils;
16
Patrick Williams84d0a882024-02-22 12:57:09 -060017auto HealthMonitor::startup() -> sdbusplus::async::task<>
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080018{
19 info("Creating Health Monitor with config size {SIZE}", "SIZE",
20 configs.size());
Patrick Williams6662be32024-02-22 13:35:46 -060021
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);
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080027
28 for (auto& [type, collectionConfig] : configs)
29 {
Patrick Williams67b8ebe2024-02-23 20:40:52 -060030 info("Creating Health Metric Collection for {TYPE}", "TYPE", type);
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080031 collections[type] =
32 std::make_unique<CollectionIntf::HealthMetricCollection>(
Patrick Williams84d0a882024-02-22 12:57:09 -060033 ctx.get_bus(), type, collectionConfig, bmcPaths);
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080034 }
Patrick Williams84d0a882024-02-22 12:57:09 -060035
36 co_await run();
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080037}
38
Patrick Williams84d0a882024-02-22 12:57:09 -060039auto HealthMonitor::run() -> sdbusplus::async::task<>
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080040{
41 info("Running Health Monitor");
Patrick Williams84d0a882024-02-22 12:57:09 -060042 while (!ctx.stop_requested())
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080043 {
Patrick Williams84d0a882024-02-22 12:57:09 -060044 for (auto& [type, collection] : collections)
45 {
Patrick Williams67b8ebe2024-02-23 20:40:52 -060046 debug("Reading Health Metric Collection for {TYPE}", "TYPE", type);
Patrick Williams84d0a882024-02-22 12:57:09 -060047 collection->read();
48 }
Jagpal Singh Gillea100c92024-03-03 18:43:53 -080049 co_await sdbusplus::async::sleep_for(
50 ctx, std::chrono::seconds(MONITOR_COLLECTION_INTERVAL));
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080051 }
52}
53
54} // namespace phosphor::health::monitor
55
56using namespace phosphor::health::monitor;
57
58int 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");
Patrick Williams84d0a882024-02-22 12:57:09 -060066 HealthMonitor healthMonitor{ctx};
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080067 ctx.request_name(healthMonitorServiceName);
68
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080069 ctx.run();
70 return 0;
71}