]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats/debug: maintain a counter of debug commands issued
authorWilly Tarreau <w@1wt.eu>
Thu, 24 Oct 2019 16:18:02 +0000 (18:18 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Oct 2019 16:38:00 +0000 (18:38 +0200)
Debug commands will usually mark the fate of the process. We'd rather
have them counted and visible in a core or in stats output than trying
to guess how a flag combination could happen. The counter is only
incremented when the command is about to be issued however, so that
failed attempts are ignored.

include/common/debug.h
include/types/stats.h
src/debug.c
src/stats.c

index f43258e923efed8ea9e3be2305b4fe67c76ee515..df855222915bbbad6591e77aa864ee977daefc18 100644 (file)
@@ -71,6 +71,7 @@
 struct task;
 struct buffer;
 extern volatile unsigned long threads_to_dump;
+extern unsigned int debug_commands_issued;
 void ha_task_dump(struct buffer *buf, const struct task *task, const char *pfx);
 void ha_thread_dump(struct buffer *buf, int thr, int calling_tid);
 void ha_thread_dump_all_to_trash();
index 8817746b36bae96cf3aa3cf05e20399eb696436d..52ea18db4a55514824c24dab8c197aba136ebecc 100644 (file)
@@ -327,6 +327,7 @@ enum info_field {
        INF_FAILED_RESOLUTIONS,
        INF_TOTAL_BYTES_OUT,
        INF_BYTES_OUT_RATE,
+       INF_DEBUG_COMMANDS_ISSUED,
 
        /* must always be the last one */
        INF_TOTAL_FIELDS
index ae788e12ff4eac103151409d4dc745e4e9b8d0e2..8df29934922ee9df55b28937a250d594c944e925 100644 (file)
@@ -36,6 +36,7 @@
  * when USE_THREAD_DUMP is set.
  */
 volatile unsigned long threads_to_dump = 0;
+unsigned int debug_commands_issued = 0;
 
 /* Dumps to the buffer some known information for the desired thread, and
  * optionally extra info for the current thread. The dump will be appended to
@@ -214,6 +215,7 @@ static int debug_parse_cli_exit(char **args, char *payload, struct appctx *appct
        if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
                return 1;
 
+       _HA_ATOMIC_ADD(&debug_commands_issued, 1);
        exit(code);
        return 1;
 }
@@ -236,6 +238,7 @@ static int debug_parse_cli_close(char **args, char *payload, struct appctx *appc
        if (!fdtab[fd].owner)
                return cli_msg(appctx, LOG_INFO, "File descriptor was already closed.\n");
 
+       _HA_ATOMIC_ADD(&debug_commands_issued, 1);
        fd_delete(fd);
        return 1;
 }
@@ -248,6 +251,7 @@ static int debug_parse_cli_delay(char **args, char *payload, struct appctx *appc
        if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
                return 1;
 
+       _HA_ATOMIC_ADD(&debug_commands_issued, 1);
        usleep((long)delay * 1000);
        return 1;
 }
@@ -260,6 +264,7 @@ static int debug_parse_cli_log(char **args, char *payload, struct appctx *appctx
        if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
                return 1;
 
+       _HA_ATOMIC_ADD(&debug_commands_issued, 1);
        chunk_reset(&trash);
        for (arg = 3; *args[arg]; arg++) {
                if (arg > 3)
@@ -280,6 +285,7 @@ static int debug_parse_cli_loop(char **args, char *payload, struct appctx *appct
        if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
                return 1;
 
+       _HA_ATOMIC_ADD(&debug_commands_issued, 1);
        gettimeofday(&curr, NULL);
        tv_ms_add(&deadline, &curr, loop);
 
@@ -295,6 +301,7 @@ static int debug_parse_cli_panic(char **args, char *payload, struct appctx *appc
        if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
                return 1;
 
+       _HA_ATOMIC_ADD(&debug_commands_issued, 1);
        ha_panic();
        return 1;
 }
@@ -309,6 +316,7 @@ static int debug_parse_cli_exec(char **args, char *payload, struct appctx *appct
        if (!cli_has_level(appctx, ACCESS_LVL_ADMIN))
                return 1;
 
+       _HA_ATOMIC_ADD(&debug_commands_issued, 1);
        chunk_reset(&trash);
        for (arg = 3; *args[arg]; arg++) {
                if (arg > 3)
@@ -353,6 +361,8 @@ static int debug_parse_cli_hex(char **args, char *payload, struct appctx *appctx
        if (!start)
                return cli_err(appctx, "Will not dump from NULL address.\n");
 
+       _HA_ATOMIC_ADD(&debug_commands_issued, 1);
+
        /* by default, dump ~128 till next block of 16 */
        len = strtoul(args[4], NULL, 0);
        if (!len)
@@ -382,6 +392,7 @@ static int debug_parse_cli_tkill(char **args, char *payload, struct appctx *appc
        if (*args[4])
                sig = atoi(args[4]);
 
+       _HA_ATOMIC_ADD(&debug_commands_issued, 1);
        if (thr)
                ha_tkill(thr - 1, sig);
        else
@@ -424,6 +435,7 @@ static int debug_parse_cli_stream(char **args, char *payload, struct appctx *app
                               );
        }
 
+       _HA_ATOMIC_ADD(&debug_commands_issued, 1);
        for (arg = 3; *args[arg]; arg++) {
                old = 0;
                end = word = args[arg];
index c152a7a3372a1ad99a89a672a88b6734485998c8..7ebf2e567cb6c3932ae819d8ec2d179a01d74e89 100644 (file)
@@ -152,6 +152,7 @@ const struct name_desc info_fields[INF_TOTAL_FIELDS] = {
        [INF_FAILED_RESOLUTIONS]             = { .name = "FailedResolutions",           .desc = "Total number of failed DNS resolutions in current worker process since started" },
        [INF_TOTAL_BYTES_OUT]                = { .name = "TotalBytesOut",               .desc = "Total number of bytes emitted by current worker process since started" },
        [INF_BYTES_OUT_RATE]                 = { .name = "BytesOutRate",                .desc = "Number of bytes emitted by current worker process over the last second" },
+       [INF_DEBUG_COMMANDS_ISSUED]          = { .name = "DebugCommandsIssued",         .desc = "Number of debug commands issued on this process (anything > 0 is unsafe)" },
 };
 
 const struct name_desc stat_fields[ST_F_TOTAL_FIELDS] = {
@@ -3463,6 +3464,7 @@ int stats_fill_info(struct field *info, int len)
        info[INF_FAILED_RESOLUTIONS]             = mkf_u32(0, dns_failed_resolutions);
        info[INF_TOTAL_BYTES_OUT]                = mkf_u64(0, global.out_bytes);
        info[INF_BYTES_OUT_RATE]                 = mkf_u64(FN_RATE, (unsigned long long)read_freq_ctr(&global.out_32bps) * 32);
+       info[INF_DEBUG_COMMANDS_ISSUED]          = mkf_u32(0, debug_commands_issued);
 
        return 1;
 }