From: Willy Tarreau Date: Tue, 22 Nov 2016 15:18:05 +0000 (+0100) Subject: REORG: cli: move "show stat" to stats.c X-Git-Tag: v1.7.0~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b812e29f6678b0691ec4bc2cd80c79b130e9d3f;p=thirdparty%2Fhaproxy.git 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 dfd8bff2fa..7fab87d07c 100644 --- a/include/proto/stats.h +++ b/include/proto/stats.h @@ -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 */ diff --git a/include/types/cli.h b/include/types/cli.h index 5c703d4d18..9c7bed5123 100644 --- a/include/types/cli.h +++ b/include/types/cli.h @@ -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 */ }; diff --git a/src/cli.c b/src/cli.c index 3662c50a3f..cdfbebf0d7 100644 --- 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; diff --git a/src/stats.c b/src/stats.c index aef6299f7a..e8796147fc 100644 --- a/src/stats.c +++ b/src/stats.c @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -45,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -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 = "", /* 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