diff options
| author | Stefan Boberg <[email protected]> | 2023-06-30 10:55:49 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2023-06-30 10:55:49 +0200 |
| commit | 912cd60c4cdfd6e0253ee1b9ed1abade09ac8b7c (patch) | |
| tree | ef0994084304dd5ce1fdd42621e36a9b34b191f7 /src/zenhttp/monitoring/httpstats.cpp | |
| parent | added zen::ChunkResolver (diff) | |
| download | zen-912cd60c4cdfd6e0253ee1b9ed1abade09ac8b7c.tar.xz zen-912cd60c4cdfd6e0253ee1b9ed1abade09ac8b7c.zip | |
various zenhttp fixes from sb/proto
* Made HttpHealthService use locks to serialize access to state
* Added ToString(HttpResponseCode HttpCode)
* Added support for JS source maps
* Moved IHttpStatsProvider/IHttpStatsService
* Enabled enumeration of stats providers
* Disabled build of HttpTestingService unless ZEN_WITH_TESTS is defined
Diffstat (limited to 'src/zenhttp/monitoring/httpstats.cpp')
| -rw-r--r-- | src/zenhttp/monitoring/httpstats.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/zenhttp/monitoring/httpstats.cpp b/src/zenhttp/monitoring/httpstats.cpp index a873b4977..1dad48d68 100644 --- a/src/zenhttp/monitoring/httpstats.cpp +++ b/src/zenhttp/monitoring/httpstats.cpp @@ -2,6 +2,8 @@ #include "zenhttp/httpstats.h" +#include <zencore/compactbinarybuilder.h> + namespace zen { HttpStatsService::HttpStatsService() : m_Log(logging::Get("stats")) @@ -15,7 +17,7 @@ HttpStatsService::~HttpStatsService() const char* HttpStatsService::BaseUri() const { - return "/stats/"; + return "/stats"; } void @@ -46,10 +48,34 @@ HttpStatsService::HandleRequest(HttpServerRequest& Request) case HttpVerb::kHead: case HttpVerb::kGet: { - RwLock::SharedLockScope _(m_Lock); - if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers)) + if (Key.empty()) { - return It->second->HandleStatsRequest(Request); + CbObjectWriter Cbo; + + Cbo.BeginArray("providers"); + + { + RwLock::SharedLockScope _(m_Lock); + for (auto& Kv : m_Providers) + { + Cbo << Kv.first; + } + } + + Cbo.EndArray(); + + Request.WriteResponse(HttpResponseCode::OK, Cbo.Save()); + } + + if (Key[0] == '/') + { + Key.remove_prefix(1); + + RwLock::SharedLockScope _(m_Lock); + if (auto It = m_Providers.find(std::string{Key}); It != end(m_Providers)) + { + return It->second->HandleStatsRequest(Request); + } } } |