aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/monitoring/httpstats.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zenhttp/monitoring/httpstats.cpp')
-rw-r--r--src/zenhttp/monitoring/httpstats.cpp34
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);
+ }
}
}