REORG: cli: move "show stat" to stats.c
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.
diff --git a/include/proto/stats.h b/include/proto/stats.h
index dfd8bff..7fab87d 100644
--- a/include/proto/stats.h
+++ b/include/proto/stats.h
@@ -104,7 +104,6 @@
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 */
diff --git a/include/types/cli.h b/include/types/cli.h
index 5c703d4..9c7bed5 100644
--- a/include/types/cli.h
+++ b/include/types/cli.h
@@ -115,7 +115,6 @@
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 */
};
diff --git a/src/cli.c b/src/cli.c
index 3662c50..cdfbebf 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -150,7 +150,6 @@
" 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 @@
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 @@
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;
diff --git a/src/stats.c b/src/stats.c
index aef6299..e879614 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -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 @@
* 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 @@
/* 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 @@
.release = NULL,
};
+__attribute__((constructor))
+static void __stat_init(void)
+{
+ cli_register_kw(&cli_kws);
+}
+
/*
* Local variables:
* c-indent-level: 8