diff options
| author | Stefan Boberg <[email protected]> | 2021-10-04 17:54:21 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-10-04 17:54:21 +0200 |
| commit | f4c6f75ed3620e777d8194bf59a24b7d6dc4200a (patch) | |
| tree | 7c3f77c7907e091270847602fc76371755f105ab /zenserver/monitoring/httpstats.cpp | |
| parent | filesystem: Added comment for future optimization opportunities in CreateDire... (diff) | |
| download | zen-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/httpstats.cpp')
| -rw-r--r-- | zenserver/monitoring/httpstats.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
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 @@ -19,14 +19,31 @@ HttpStatsService::BaseUri() const } 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; } } |