-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhealth_monitor.cpp
71 lines (56 loc) · 2.02 KB
/
health_monitor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "config.h"
#include "health_monitor.hpp"
#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/async.hpp>
#include <xyz/openbmc_project/Inventory/Item/Bmc/common.hpp>
#include <xyz/openbmc_project/Inventory/Item/common.hpp>
PHOSPHOR_LOG2_USING;
namespace phosphor::health::monitor
{
using namespace phosphor::health::utils;
auto HealthMonitor::startup() -> sdbusplus::async::task<>
{
info("Creating Health Monitor with config size {SIZE}", "SIZE",
configs.size());
static constexpr auto bmcIntf = sdbusplus::common::xyz::openbmc_project::
inventory::item::Bmc::interface;
static constexpr auto invPath = sdbusplus::common::xyz::openbmc_project::
inventory::Item::namespace_path;
auto bmcPaths = co_await findPaths(ctx, bmcIntf, invPath);
for (auto& [type, collectionConfig] : configs)
{
info("Creating Health Metric Collection for {TYPE}", "TYPE", type);
collections[type] =
std::make_unique<CollectionIntf::HealthMetricCollection>(
ctx.get_bus(), type, collectionConfig, bmcPaths);
}
co_await run();
}
auto HealthMonitor::run() -> sdbusplus::async::task<>
{
info("Running Health Monitor");
while (!ctx.stop_requested())
{
for (auto& [type, collection] : collections)
{
debug("Reading Health Metric Collection for {TYPE}", "TYPE", type);
collection->read();
}
co_await sdbusplus::async::sleep_for(
ctx, std::chrono::seconds(MONITOR_COLLECTION_INTERVAL));
}
}
} // namespace phosphor::health::monitor
using namespace phosphor::health::monitor;
int main()
{
constexpr auto path = MetricIntf::ValueIntf::Value::namespace_path::value;
sdbusplus::async::context ctx;
sdbusplus::server::manager_t manager{ctx, path};
constexpr auto healthMonitorServiceName = "xyz.openbmc_project.HealthMon";
info("Creating health monitor");
HealthMonitor healthMonitor{ctx};
ctx.request_name(healthMonitorServiceName);
ctx.run();
return 0;
}