]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stream/stats: Expose the total number of streams ever created in stats
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 27 Sep 2024 15:16:00 +0000 (17:16 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 30 Sep 2024 14:55:53 +0000 (16:55 +0200)
A shared counter is added in the thread context to track the total number of
streams created on the thread. This number is then reported in stats. It
will be a useful information to diagnose some bugs.

include/haproxy/stats-t.h
include/haproxy/tinfo-t.h
src/stats.c
src/stream.c

index bd4521451584456105429b4c19b02869c9349fa9..b9df6c824daa3e5d3b56cb1ccf72ffe859413138 100644 (file)
@@ -335,6 +335,7 @@ enum stat_idx_info {
        ST_I_INF_BOOTTIME_MS,
        ST_I_INF_NICED_TASKS,
        ST_I_INF_CURR_STRM,
+       ST_I_INF_CUM_STRM,
 
        /* must always be the last one */
        ST_I_INF_MAX
index 4c6d39fab37c8119a6345071fda51bfbb673bce3..547837554e8b2ca27e8372eb497a61d251fdabfb 100644 (file)
@@ -180,9 +180,10 @@ struct thread_ctx {
        unsigned long long out_bytes;           /* total #of bytes emitted */
        unsigned long long spliced_out_bytes;   /* total #of bytes emitted though a kernel pipe */
        struct buffer *thread_dump_buffer;      /* NULL out of dump, valid during a dump, 0x01 once done */
+       unsigned long long total_streams;       /* Total number of streams created on this thread */
        unsigned int stream_cnt;                /* Number of streams attached to this thread */
 
-       // around 52 bytes here for shared variables
+       // around 44 bytes here for shared variables
 
        ALWAYS_ALIGN(128);
 };
index 346f11e291921921c0823d41cbac16defb392b64..93f3e8e826d3df764cbe6b168700ed6030732754 100644 (file)
@@ -169,6 +169,7 @@ const struct name_desc stat_cols_info[ST_I_INF_MAX] = {
        [ST_I_INF_BOOTTIME_MS]                    = { .name = "BootTime_ms",                 .desc = "How long ago it took to parse and process the config before being ready (milliseconds)" },
        [ST_I_INF_NICED_TASKS]                    = { .name = "Niced_tasks",                 .desc = "Total number of active tasks+tasklets in the current worker process (Run_queue) that are niced" },
        [ST_I_INF_CURR_STRM]                      = { .name = "CurrStreams",                 .desc = "Current number of streams on this worker process" },
+       [ST_I_INF_CUM_STRM]                       = { .name = "CurrStreams",                 .desc = "Total number of streams created on this worker process since started" },
 };
 
 /* one line of info */
@@ -692,7 +693,7 @@ static int stats_dump_typed_info_fields(struct buffer *out,
 int stats_fill_info(struct field *line, int len, uint flags)
 {
        struct buffer *out = get_trash_chunk();
-       uint64_t glob_out_bytes, glob_spl_bytes, glob_out_b32, glob_curr_strms;
+       uint64_t glob_out_bytes, glob_spl_bytes, glob_out_b32, glob_curr_strms, glob_cum_strms;
        uint up_sec, up_usec;
        ullong up;
        ulong boot;
@@ -708,12 +709,13 @@ int stats_fill_info(struct field *line, int len, uint flags)
 #endif
 
        /* sum certain per-thread totals (mostly byte counts) */
-       glob_out_bytes = glob_spl_bytes = glob_out_b32 = glob_curr_strms = 0;
+       glob_out_bytes = glob_spl_bytes = glob_out_b32 = glob_curr_strms = glob_cum_strms = 0;
        for (thr = 0; thr < global.nbthread; thr++) {
                glob_out_bytes += HA_ATOMIC_LOAD(&ha_thread_ctx[thr].out_bytes);
                glob_spl_bytes += HA_ATOMIC_LOAD(&ha_thread_ctx[thr].spliced_out_bytes);
                glob_out_b32   += read_freq_ctr(&ha_thread_ctx[thr].out_32bps);
                glob_curr_strms+= HA_ATOMIC_LOAD(&ha_thread_ctx[thr].stream_cnt);
+               glob_cum_strms += HA_ATOMIC_LOAD(&ha_thread_ctx[thr].total_streams);
        }
        glob_out_b32 *= 32; // values are 32-byte units
 
@@ -820,6 +822,7 @@ int stats_fill_info(struct field *line, int len, uint flags)
        line[ST_I_INF_BOOTTIME_MS]                    = mkf_u32(FN_DURATION, boot);
        line[ST_I_INF_NICED_TASKS]                    = mkf_u32(0, total_niced_running_tasks());
        line[ST_I_INF_CURR_STRM]                      = mkf_u64(0, glob_curr_strms);
+       line[ST_I_INF_CUM_STRM]                       = mkf_u64(0, glob_cum_strms);
 
        return 1;
 }
index 7f494dde4ee732b1cf608b849c584719ea32614e..f0cb8cf8016aca0eb82603047751269b6a8c4de5 100644 (file)
@@ -546,6 +546,7 @@ struct stream *stream_new(struct session *sess, struct stconn *sc, struct buffer
        s->tunnel_timeout = TICK_ETERNITY;
 
        LIST_APPEND(&th_ctx->streams, &s->list);
+       _HA_ATOMIC_INC(&th_ctx->total_streams);
        _HA_ATOMIC_INC(&th_ctx->stream_cnt);
 
        if (flt_stream_init(s) < 0 || flt_stream_start(s) < 0)