blob: 15d411540bd845d8ca7e410f44c354b5576354fb [file] [log] [blame]
#include "request_stats_store_http.hpp"
#include "async_resp.hpp"
#include "logging.hpp"
#include "request_stats.hpp"
#include <nlohmann/json.hpp>
#include <algorithm>
#include <charconv>
#include <string_view>
namespace managedStore
{
class RequestStatsStoreHttp
{
public:
RequestStatsStoreHttp() = delete;
~RequestStatsStoreHttp() = delete;
RequestStatsStoreHttp(const RequestStatsStoreHttp&) = default;
RequestStatsStoreHttp& operator=(const RequestStatsStoreHttp&) = default;
RequestStatsStoreHttp(RequestStatsStoreHttp&&) = default;
RequestStatsStoreHttp& operator=(RequestStatsStoreHttp&&) = default;
static void
requestGetStats(App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
(void)app;
BMCWEB_LOG_STATEFUL_DEBUG
<< "=> RequestStatsStoreHttp::requestGetStats:"
<< " target: " << req.target() << " method: " << req.method()
<< " body: " << req.body();
auto store = managedStore::RequestStatsStore::instance();
asyncResp->res.jsonValue["store"] = store.toJson();
}
static void
requestClearStats(App& app, const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
(void)app;
BMCWEB_LOG_STATEFUL_DEBUG
<< "=> RequestStatsStoreHttp::requestClearStats"
<< " target: " << req.target() << " method: " << req.method()
<< " body: " << req.body();
// ManagedObjectStore instance:
managedStore::RequestStatsStore& store =
managedStore::RequestStatsStore::instance();
store.clear();
asyncResp->res.jsonValue["store"] = store.toJson();
}
};
void requestRoutesRequestStatsStore(App& app)
{
BMCWEB_ROUTE(app, "/debug/request_stats_store")
.methods(boost::beast::http::verb::get)(
[&app](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
RequestStatsStoreHttp::requestGetStats(app, req, asyncResp);
});
BMCWEB_ROUTE(app, "/debug/request_stats_store/clear")
.methods(boost::beast::http::verb::post)(
[&app](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
RequestStatsStoreHttp::requestClearStats(app, req, asyncResp);
});
}
} // namespace managedStore