summaryrefslogtreecommitdiff
path: root/redfish-core/lib
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2023-01-23 22:28:10 +0300
committerEd Tanous <ed@tanous.net>2023-03-02 02:37:27 +0300
commit5ace29d2665cb70688edca5f9ca9e362958ce6b7 (patch)
treea46bec4702ee79bc3a952626048a43f5d619858a /redfish-core/lib
parente68d1be018a203970377d652005bafa14c4bf2f0 (diff)
downloadbmcweb-5ace29d2665cb70688edca5f9ca9e362958ce6b7.tar.xz
Implement ManagerDiagnosticData/ServiceRootUptimeSeconds
This property was added in Redfish 2022.2 to denote how long this service has been up and available. This implementation opts to go to systemd to get the bmcweb service uptime rather than track it through internal process state, given that systemd already has an API that tracks the bmcweb uptime, and bmcweb attempts to keep as little state as possible. Given that we already have helper functions that give durations in milliseconds precision, this patchset opts to keep the millisecond granularity, rather than dropping to microsecond precision of the systemd API. There are no use cases that would require microsecond precision, so this patchset opts for lower complexity. Tested: Redfish service validator passes. GET /redfish/v1/Managers/bmc/ManagerDiagnosticData Returns a ServiceRootUptime property. Value matches systemctl status bmcweb. systemctl restart bmcweb, causes counter to reset. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: Ie1b82c5150f3374faf0ce376402eba410e59891d
Diffstat (limited to 'redfish-core/lib')
-rw-r--r--redfish-core/lib/manager_diagnostic_data.hpp51
1 files changed, 50 insertions, 1 deletions
diff --git a/redfish-core/lib/manager_diagnostic_data.hpp b/redfish-core/lib/manager_diagnostic_data.hpp
index 66fc661131..14b75feaf1 100644
--- a/redfish-core/lib/manager_diagnostic_data.hpp
+++ b/redfish-core/lib/manager_diagnostic_data.hpp
@@ -9,12 +9,59 @@
#include "routing.hpp"
#include <nlohmann/json.hpp>
+#include <sdbusplus/asio/property.hpp>
#include <string>
namespace redfish
{
+inline void
+ afterGetManagerStartTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
+ const boost::system::error_code& ec,
+ uint64_t bmcwebResetTime)
+{
+ if (ec)
+ {
+ // Not all servers will be running in systemd, so ignore the error.
+ return;
+ }
+ using std::chrono::steady_clock;
+
+ std::chrono::duration<steady_clock::rep, std::micro> usReset{
+ bmcwebResetTime};
+ steady_clock::time_point resetTime{usReset};
+
+ steady_clock::time_point now = steady_clock::now();
+
+ steady_clock::duration runTime = now - resetTime;
+
+ if (runTime < steady_clock::duration::zero())
+ {
+ BMCWEB_LOG_CRITICAL << "Uptime was negative????";
+ messages::internalError(aResp->res);
+ return;
+ }
+
+ // Floor to the closest millisecond
+ using Milli = std::chrono::duration<steady_clock::rep, std::milli>;
+ Milli milli = std::chrono::floor<Milli>(runTime);
+
+ using SecondsFloat = std::chrono::duration<double>;
+ SecondsFloat sec = std::chrono::duration_cast<SecondsFloat>(milli);
+
+ aResp->res.jsonValue["ServiceRootUptimeSeconds"] = sec.count();
+}
+
+inline void
+ managerGetServiceRootUptime(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
+{
+ sdbusplus::asio::getProperty<uint64_t>(
+ *crow::connections::systemBus, "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1/unit/bmcweb_2eservice",
+ "org.freedesktop.systemd1.Unit", "ActiveEnterTimestampMonotonic",
+ std::bind_front(afterGetManagerStartTime, aResp));
+}
/**
* handleManagerDiagnosticData supports ManagerDiagnosticData.
* It retrieves BMC health information from various DBus resources and returns
@@ -29,11 +76,13 @@ inline void handleManagerDiagnosticDataGet(
return;
}
asyncResp->res.jsonValue["@odata.type"] =
- "#ManagerDiagnosticData.v1_0_0.ManagerDiagnosticData";
+ "#ManagerDiagnosticData.v1_2_0.ManagerDiagnosticData";
asyncResp->res.jsonValue["@odata.id"] =
"/redfish/v1/Managers/bmc/ManagerDiagnosticData";
asyncResp->res.jsonValue["Id"] = "ManagerDiagnosticData";
asyncResp->res.jsonValue["Name"] = "Manager Diagnostic Data";
+
+ managerGetServiceRootUptime(asyncResp);
}
inline void requestRoutesManagerDiagnosticData(App& app)