From fdcd7fca10dd00bb724bca7d27125d21d2cb5357 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 9 Jun 2017 01:00:21 +0200 Subject: [PATCH] Add an exported metrics for number of connected clients. --- httpd.cpp | 3 +++ httpd.h | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/httpd.cpp b/httpd.cpp index e76cc80..2b19779 100644 --- a/httpd.cpp +++ b/httpd.cpp @@ -22,6 +22,7 @@ using namespace std; HTTPD::HTTPD() { + global_metrics.register_int_metric("num_connected_clients", &metric_num_connected_clients); } HTTPD::~HTTPD() @@ -94,6 +95,7 @@ int HTTPD::answer_to_connection(MHD_Connection *connection, unique_lock lock(streams_mutex); streams.insert(stream); } + ++metric_num_connected_clients; *con_cls = stream; // Does not strictly have to be equal to MUX_BUFFER_SIZE. @@ -119,6 +121,7 @@ void HTTPD::free_stream(void *cls) delete stream; httpd->streams.erase(stream); } + --httpd->metric_num_connected_clients; } ssize_t HTTPD::Stream::reader_callback_thunk(void *cls, uint64_t pos, char *buf, size_t max) diff --git a/httpd.h b/httpd.h index 902745a..6e37c52 100644 --- a/httpd.h +++ b/httpd.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -78,6 +79,9 @@ private: std::mutex streams_mutex; std::set streams; // Not owned. std::string header; + + // Metrics. + std::atomic metric_num_connected_clients{0}; }; #endif // !defined(_HTTPD_H) -- 2.39.2