add an ealry version of active-connections and inactive-connections to stats
@@ -3324,6 +3324,31 @@ err:
}
#endif
+static int count_linklist(const h2o_linklist_t *list)
+{
+ int count = 0;
+ for (const h2o_linklist_t *node = list->next; node != list; node = node->next) {
+ count++;
+ }
+ return count;
+}
+
+static void count_connections(int *n_actives, int *n_inactives)
+{
+ int active = 0, inactive = 0;
+ for (size_t i = 0; i < conf.thread_map.size; ++i) {
+ const h2o_context_t *ctx = &conf.threads[i].ctx;
+ active += count_linklist(&ctx->http1._active_conns);
+ active += count_linklist(&ctx->http2._active_conns);
+ active += count_linklist(&ctx->http3._active_conns);
+ inactive += count_linklist(&ctx->http1._inactive_conns);
+ inactive += count_linklist(&ctx->http2._inactive_conns);
+ inactive += count_linklist(&ctx->http3._inactive_conns);
+ }
+ *n_actives = active;
+ *n_inactives = inactive;
+}
+
static h2o_iovec_t on_extra_status(void *unused, h2o_globalconf_t *_conf, h2o_req_t *req)
{
#define BUFSIZE (16 * 1024)
@@ -3337,6 +3362,9 @@ static h2o_iovec_t on_extra_status(void *unused, h2o_globalconf_t *_conf, h2o_re
if ((generation = getenv("SERVER_STARTER_GENERATION")) == NULL)
generation = "null";
+ int n_actives, n_inactives;
+ count_connections(&n_actives, &n_inactives);
+
ret.base = h2o_mem_alloc_pool(&req->pool, char, BUFSIZE);
ret.len = snprintf(ret.base, BUFSIZE,
",\n"
@@ -3350,9 +3378,14 @@ static h2o_iovec_t on_extra_status(void *unused, h2o_globalconf_t *_conf, h2o_re
" \"max-connections\": %d,\n"
" \"listeners\": %zu,\n"
" \"worker-threads\": %zu,\n"
+ " \"active-connections\": %d,\n"
+ " \"inactive-connections\": %d,\n"
" \"num-sessions\": %lu",
OpenSSL_version(OPENSSL_VERSION), current_time, restart_time, (uint64_t)(now - conf.launch_time), generation,
- num_connections(0), conf.max_connections, conf.num_listeners, conf.thread_map.size, num_sessions(0));
+ num_connections(0), conf.max_connections, conf.num_listeners, conf.thread_map.size,
+ n_actives, n_inactives,
+ num_sessions(0)
+ );
assert(ret.len < BUFSIZE);
#if JEMALLOC_STATS == 1
