enable health_monitor new implementation
Add health_monitor interface and implementation. Enable the
health_monitor from existing healthMonitor flow.
This change is in relation to following design and D-Bus interface
update -
https://gerrit.openbmc.org/c/openbmc/docs/+/64917
https://gerrit.openbmc.org/c/openbmc/phosphor-dbus-interfaces/+/64914
Tested:
```
busctl tree xyz.openbmc_project.HealthMon
`- /xyz
`- /xyz/openbmc_project
`- /xyz/openbmc_project/metric
`- /xyz/openbmc_project/metric/bmc
|- /xyz/openbmc_project/metric/bmc/cpu
| |- /xyz/openbmc_project/metric/bmc/cpu/kernel
| |- /xyz/openbmc_project/metric/bmc/cpu/total
| `- /xyz/openbmc_project/metric/bmc/cpu/user
|- /xyz/openbmc_project/metric/bmc/memory
| |- /xyz/openbmc_project/metric/bmc/memory/available
| |- /xyz/openbmc_project/metric/bmc/memory/buffered_and_cached
| |- /xyz/openbmc_project/metric/bmc/memory/free
| |- /xyz/openbmc_project/metric/bmc/memory/shared
| `- /xyz/openbmc_project/metric/bmc/memory/total
`- /xyz/openbmc_project/metric/bmc/storage
|- /xyz/openbmc_project/metric/bmc/storage/rw
`- /xyz/openbmc_project/metric/bmc/storage/tmp
curl -k https://localhost:8443/redfish/v1/Managers/bmc/ManagerDiagnosticData
--user "root:0penBmc"
{
"@odata.id": "/redfish/v1/Managers/bmc/ManagerDiagnosticData",
"@odata.type": "#ManagerDiagnosticData.v1_2_0.ManagerDiagnosticData",
"FreeStorageSpaceKiB": 3,
"Id": "ManagerDiagnosticData",
"MemoryStatistics": {
"AvailableBytes": 354029533,
"BuffersAndCacheBytes": 79077333,
"FreeBytes": 291730033,
"SharedBytes": 11876000,
"TotalBytes": 425516000
},
"Name": "Manager Diagnostic Data",
"ProcessorStatistics": {
"KernelPercent": 16.1534,
"UserPercent": 10.6638
},
"ServiceRootUptimeSeconds": 834.753
}
```
Change-Id: I1e9fac226b438f0556cb20321f1f2b6d51af7dbc
Signed-off-by: Jagpal Singh Gill <paligill@gmail.com>
diff --git a/health_monitor.cpp b/health_monitor.cpp
new file mode 100644
index 0000000..b839ae7
--- /dev/null
+++ b/health_monitor.cpp
@@ -0,0 +1,66 @@
+#include "health_monitor.hpp"
+
+#include <phosphor-logging/lg2.hpp>
+#include <sdbusplus/async.hpp>
+
+PHOSPHOR_LOG2_USING;
+
+namespace phosphor::health::monitor
+{
+
+using namespace phosphor::health::utils;
+
+void HealthMonitor::create()
+{
+ info("Creating Health Monitor with config size {SIZE}", "SIZE",
+ configs.size());
+ constexpr auto BMCInventoryItem = "xyz.openbmc_project.Inventory.Item.Bmc";
+ auto bmcPaths = findPaths(bus, BMCInventoryItem);
+
+ for (auto& [type, collectionConfig] : configs)
+ {
+ info("Creating Health Metric Collection for {TYPE}", "TYPE",
+ std::to_underlying(type));
+ collections[type] =
+ std::make_unique<CollectionIntf::HealthMetricCollection>(
+ bus, type, collectionConfig, bmcPaths);
+ }
+}
+
+void HealthMonitor::run()
+{
+ info("Running Health Monitor");
+ for (auto& [type, collection] : collections)
+ {
+ debug("Reading Health Metric Collection for {TYPE}", "TYPE",
+ std::to_underlying(type));
+ collection->read();
+ }
+}
+
+} // 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.get_bus()};
+ ctx.request_name(healthMonitorServiceName);
+
+ ctx.spawn([&]() -> sdbusplus::async::task<> {
+ while (!ctx.stop_requested())
+ {
+ healthMonitor.run();
+ co_await sdbusplus::async::sleep_for(ctx, std::chrono::seconds(5));
+ }
+ }());
+
+ ctx.run();
+ return 0;
+}