blob: 0c732b0dea019c0fcf003482f71147e51ea7b827 [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
Patrick Williams84d0a882024-02-22 12:57:09 -060013auto HealthMonitor::startup() -> sdbusplus::async::task<>
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080014{
15 info("Creating Health Monitor with config size {SIZE}", "SIZE",
16 configs.size());
17 constexpr auto BMCInventoryItem = "xyz.openbmc_project.Inventory.Item.Bmc";
Patrick Williams84d0a882024-02-22 12:57:09 -060018 auto bmcPaths = findPaths(ctx.get_bus(), BMCInventoryItem);
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080019
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>(
Patrick Williams84d0a882024-02-22 12:57:09 -060026 ctx.get_bus(), type, collectionConfig, bmcPaths);
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080027 }
Patrick Williams84d0a882024-02-22 12:57:09 -060028
29 co_await run();
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080030}
31
Patrick Williams84d0a882024-02-22 12:57:09 -060032auto HealthMonitor::run() -> sdbusplus::async::task<>
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080033{
34 info("Running Health Monitor");
Patrick Williams84d0a882024-02-22 12:57:09 -060035 while (!ctx.stop_requested())
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080036 {
Patrick Williams84d0a882024-02-22 12:57:09 -060037 for (auto& [type, collection] : collections)
38 {
39 debug("Reading Health Metric Collection for {TYPE}", "TYPE",
40 std::to_underlying(type));
41 collection->read();
42 }
43 co_await sdbusplus::async::sleep_for(ctx, std::chrono::seconds(5));
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080044 }
45}
46
47} // namespace phosphor::health::monitor
48
49using namespace phosphor::health::monitor;
50
51int main()
52{
53 constexpr auto path = MetricIntf::ValueIntf::Value::namespace_path::value;
54 sdbusplus::async::context ctx;
55 sdbusplus::server::manager_t manager{ctx, path};
56 constexpr auto healthMonitorServiceName = "xyz.openbmc_project.HealthMon";
57
58 info("Creating health monitor");
Patrick Williams84d0a882024-02-22 12:57:09 -060059 HealthMonitor healthMonitor{ctx};
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080060 ctx.request_name(healthMonitorServiceName);
61
Jagpal Singh Gill81da1372023-12-15 17:01:03 -080062 ctx.run();
63 return 0;
64}