aboutsummaryrefslogtreecommitdiff
path: root/zenserver/monitoring/httpstatus.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-10-04 17:54:21 +0200
committerStefan Boberg <[email protected]>2021-10-04 17:54:21 +0200
commitf4c6f75ed3620e777d8194bf59a24b7d6dc4200a (patch)
tree7c3f77c7907e091270847602fc76371755f105ab /zenserver/monitoring/httpstatus.cpp
parentfilesystem: Added comment for future optimization opportunities in CreateDire... (diff)
downloadzen-f4c6f75ed3620e777d8194bf59a24b7d6dc4200a.tar.xz
zen-f4c6f75ed3620e777d8194bf59a24b7d6dc4200a.zip
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
Diffstat (limited to 'zenserver/monitoring/httpstatus.cpp')
-rw-r--r--zenserver/monitoring/httpstatus.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/zenserver/monitoring/httpstatus.cpp b/zenserver/monitoring/httpstatus.cpp
index c18bf6c1f..e12662b1c 100644
--- a/zenserver/monitoring/httpstatus.cpp
+++ b/zenserver/monitoring/httpstatus.cpp
@@ -15,7 +15,14 @@ HttpStatusService::~HttpStatusService()
const char*
HttpStatusService::BaseUri() const
{
- return "/statUs/";
+ return "/status/";
+}
+
+void
+HttpStatusService::RegisterHandler(std::string_view Id, IHttpStatusProvider& Provider)
+{
+ RwLock::ExclusiveLockScope _(m_Lock);
+ m_Providers.insert_or_assign(std::string(Id), &Provider);
}
void
@@ -23,10 +30,20 @@ HttpStatusService::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->HandleStatusRequest(Request);
+ }
+
+ [[fallthrough]];
+ default:
+ return;
}
}