]> git.sesse.net Git - nageru/blobdiff - httpd.cpp
Add an exported metrics for number of connected clients.
[nageru] / httpd.cpp
index e76cc80634ca9b2b03cd253d69b0641674693d19..2b19779ea450f253a2dee0e689b121eda4733335 100644 (file)
--- 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<mutex> 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)