]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: cli: move "show stat" to stats.c
authorWilly Tarreau <w@1wt.eu>
Tue, 22 Nov 2016 15:18:05 +0000 (16:18 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2016 15:59:27 +0000 (16:59 +0100)
Move the "show stat" command to stats.c using the CLI keyword API
to register it on the CLI. The stats_dump_stat_to_buffer() function
is now static again.

include/proto/stats.h
include/types/cli.h
src/cli.c
src/stats.c

index dfd8bff2fae8b9aa1208021918edfe5278de7334..7fab87d07c41f705dd6f06311b2bcafde6ed8586 100644 (file)
@@ -104,7 +104,6 @@ void stats_io_handler(struct stream_interface *si);
 int stats_emit_raw_data_field(struct chunk *out, const struct field *f);
 int stats_emit_typed_data_field(struct chunk *out, const struct field *f);
 int stats_emit_field_tags(struct chunk *out, const struct field *f, char delim);
-int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri);
 
 #endif /* _PROTO_STATS_H */
 
index 5c703d4d18bdfbe3e876645dfc2fc16fd6569147..9c7bed5123402411e6db647c73d7d982ae06cb9b 100644 (file)
@@ -115,7 +115,6 @@ enum {
        STAT_CLI_O_TAB,      /* dump tables */
        STAT_CLI_O_CLR,      /* clear tables */
        STAT_CLI_O_SET,      /* set entries in tables */
-       STAT_CLI_O_STAT,     /* dump stats */
        STAT_CLI_O_ENV,      /* dump environment */
        STAT_CLI_O_CUSTOM,   /* custom callback pointer */
 };
index 3662c50a3f1fa136c7127efcc10dc3927183dc06..cdfbebf0d798d81a7ea3c52c212cb8763b9e88fa 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -150,7 +150,6 @@ static const char stats_sock_usage_msg[] =
        "  quit           : disconnect\n"
        "  show env [var] : dump environment variables known to the process\n"
        "  show info      : report information about the running process\n"
-       "  show stat      : report counters for each proxy and server\n"
        "  show errors    : report last request and response errors for each proxy\n"
        "  show table [id]: report table usage stats or dump this table's contents\n"
        "  set table [id] : update or create a table entry's data\n"
@@ -1077,21 +1076,6 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
                                appctx->st2 = STAT_ST_END;
                        }
                }
-               else if (strcmp(args[1], "stat") == 0) {
-                       if (*args[2] && *args[3] && *args[4]) {
-                               appctx->ctx.stats.flags |= STAT_BOUND;
-                               appctx->ctx.stats.iid = atoi(args[2]);
-                               appctx->ctx.stats.type = atoi(args[3]);
-                               appctx->ctx.stats.sid = atoi(args[4]);
-                               if (strcmp(args[5], "typed") == 0)
-                                       appctx->ctx.stats.flags |= STAT_FMT_TYPED;
-                       }
-                       else if (strcmp(args[2], "typed") == 0)
-                               appctx->ctx.stats.flags |= STAT_FMT_TYPED;
-
-                       appctx->st2 = STAT_ST_INIT;
-                       appctx->st0 = STAT_CLI_O_STAT; // stats_dump_stat_to_buffer
-               }
                else if (strcmp(args[1], "info") == 0) {
                        if (strcmp(args[2], "typed") == 0)
                                appctx->ctx.stats.flags |= STAT_FMT_TYPED;
@@ -1827,10 +1811,6 @@ static void cli_io_handler(struct appctx *appctx)
                                if (stats_dump_info_to_buffer(si))
                                        appctx->st0 = STAT_CLI_PROMPT;
                                break;
-                       case STAT_CLI_O_STAT:
-                               if (stats_dump_stat_to_buffer(si, NULL))
-                                       appctx->st0 = STAT_CLI_PROMPT;
-                               break;
                        case STAT_CLI_O_ERR:    /* errors dump */
                                if (stats_dump_errors_to_buffer(si))
                                        appctx->st0 = STAT_CLI_PROMPT;
index aef6299f7af1fa1012bcbb61b3f111068542e3f0..e8796147fcba062a67b8f46ea0a7f50564d21b38 100644 (file)
@@ -38,6 +38,7 @@
 #include <common/base64.h>
 
 #include <types/applet.h>
+#include <types/cli.h>
 #include <types/global.h>
 #include <types/dns.h>
 #include <types/stats.h>
@@ -45,6 +46,7 @@
 #include <proto/backend.h>
 #include <proto/channel.h>
 #include <proto/checks.h>
+#include <proto/cli.h>
 #include <proto/compression.h>
 #include <proto/stats.h>
 #include <proto/fd.h>
@@ -2199,7 +2201,7 @@ static void stats_dump_html_end()
  * and the stream must be closed, or -1 in case of any error. This function is
  * used by both the CLI and the HTTP handlers.
  */
-int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri)
+static int stats_dump_stat_to_buffer(struct stream_interface *si, struct uri_auth *uri)
 {
        struct appctx *appctx = __objt_appctx(si->end);
        struct channel *rep = si_ic(si);
@@ -2811,6 +2813,37 @@ static void http_stats_io_handler(struct appctx *appctx)
        /* just to make gcc happy */ ;
 }
 
+static int cli_parse_show_stat(char **args, struct appctx *appctx, void *private)
+{
+       if (*args[2] && *args[3] && *args[4]) {
+               appctx->ctx.stats.flags |= STAT_BOUND;
+               appctx->ctx.stats.iid = atoi(args[2]);
+               appctx->ctx.stats.type = atoi(args[3]);
+               appctx->ctx.stats.sid = atoi(args[4]);
+               if (strcmp(args[5], "typed") == 0)
+                       appctx->ctx.stats.flags |= STAT_FMT_TYPED;
+       }
+       else if (strcmp(args[2], "typed") == 0)
+               appctx->ctx.stats.flags |= STAT_FMT_TYPED;
+
+       appctx->st2 = STAT_ST_INIT;
+       return 0;
+}
+
+/* This I/O handler runs as an applet embedded in a stream interface. It is
+ * used to send raw stats over a socket.
+ */
+static int cli_io_handler_dump_stat(struct appctx *appctx)
+{
+       return stats_dump_stat_to_buffer(appctx->owner, NULL);
+}
+
+/* register cli keywords */
+static struct cli_kw_list cli_kws = {{ },{
+       { { "show", "stat",  NULL }, "show stat      : report counters for each proxy and server", cli_parse_show_stat, cli_io_handler_dump_stat, NULL },
+       {{},}
+}};
+
 struct applet http_stats_applet = {
        .obj_type = OBJ_TYPE_APPLET,
        .name = "<STATS>", /* used for logging */
@@ -2818,6 +2851,12 @@ struct applet http_stats_applet = {
        .release = NULL,
 };
 
+__attribute__((constructor))
+static void __stat_init(void)
+{
+       cli_register_kw(&cli_kws);
+}
+
 /*
  * Local variables:
  *  c-indent-level: 8