blob: 9670854bd1a63a7b163fe36fa52f09f380447c99 [file] [log] [blame]
#include "request_stats_store_http.hpp"
#include <memory>
#include <string_view>
#include "app.hpp"
#include "http_request.hpp"
#include "logging.hpp"
#include "async_resp.hpp"
#include "request_stats.hpp"
#include <nlohmann/json.hpp>
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