From cceed531be3fc89f034e79a599a72e28ebe7d32b Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 4 Oct 2021 15:24:53 +0200 Subject: monitoring: added stubs for /stats and /status endpoints this is a tactical check-in to allow me to merge some other changes --- zenserver/monitoring/httpstats.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 zenserver/monitoring/httpstats.cpp (limited to 'zenserver/monitoring/httpstats.cpp') diff --git a/zenserver/monitoring/httpstats.cpp b/zenserver/monitoring/httpstats.cpp new file mode 100644 index 000000000..a82cfda50 --- /dev/null +++ b/zenserver/monitoring/httpstats.cpp @@ -0,0 +1,33 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "httpstats.h" + +namespace zen { + +HttpStatsService::HttpStatsService() : m_Log(logging::Get("stats")) +{ +} + +HttpStatsService::~HttpStatsService() +{ +} + +const char* +HttpStatsService::BaseUri() const +{ + return "/stats/"; +} + +void +HttpStatsService::HandleRequest(HttpServerRequest& Request) +{ + using namespace std::literals; + + switch (Request.RequestVerb()) + { + case HttpVerb::kGet: + return Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, u8"OK!"sv); + } +} + +} // namespace zen -- cgit v1.2.3 From f4c6f75ed3620e777d8194bf59a24b7d6dc4200a Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 4 Oct 2021 17:54:21 +0200 Subject: stats: Implemented new stats endpoint Stats are exposed under /stats/{id}, so for example structured cache stats are exposed under /stats/z$ The separate endpoint makes it easier to separate request handling to ensure stats/status endpoints still respond if the regular request queue is somehow saturated or otherwise not behaving There is also a /status endpoint which is similar and is targeted towards lightweight health monitoring --- zenserver/monitoring/httpstats.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'zenserver/monitoring/httpstats.cpp') diff --git a/zenserver/monitoring/httpstats.cpp b/zenserver/monitoring/httpstats.cpp index a82cfda50..de04294d0 100644 --- a/zenserver/monitoring/httpstats.cpp +++ b/zenserver/monitoring/httpstats.cpp @@ -18,15 +18,32 @@ HttpStatsService::BaseUri() const return "/stats/"; } +void +HttpStatsService::RegisterHandler(std::string_view Id, IHttpStatsProvider& Provider) +{ + RwLock::ExclusiveLockScope _(m_Lock); + m_Providers.insert_or_assign(std::string(Id), &Provider); +} + void HttpStatsService::HandleRequest(HttpServerRequest& Request) { using namespace std::literals; + std::string_view Key = Request.RelativeUri(); + switch (Request.RequestVerb()) { + case HttpVerb::kHead: case HttpVerb::kGet: - return Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kText, u8"OK!"sv); + if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers)) + { + return It->second->HandleStatsRequest(Request); + } + + [[fallthrough]]; + default: + return; } } -- cgit v1.2.3