mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 06:11:32 +02:00
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.
This commit is contained in:
parent
6b16094355
commit
2b812e29f6
@ -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_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_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_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 */
|
#endif /* _PROTO_STATS_H */
|
||||||
|
|
||||||
|
@ -115,7 +115,6 @@ enum {
|
|||||||
STAT_CLI_O_TAB, /* dump tables */
|
STAT_CLI_O_TAB, /* dump tables */
|
||||||
STAT_CLI_O_CLR, /* clear tables */
|
STAT_CLI_O_CLR, /* clear tables */
|
||||||
STAT_CLI_O_SET, /* set entries in tables */
|
STAT_CLI_O_SET, /* set entries in tables */
|
||||||
STAT_CLI_O_STAT, /* dump stats */
|
|
||||||
STAT_CLI_O_ENV, /* dump environment */
|
STAT_CLI_O_ENV, /* dump environment */
|
||||||
STAT_CLI_O_CUSTOM, /* custom callback pointer */
|
STAT_CLI_O_CUSTOM, /* custom callback pointer */
|
||||||
};
|
};
|
||||||
|
20
src/cli.c
20
src/cli.c
@ -150,7 +150,6 @@ static const char stats_sock_usage_msg[] =
|
|||||||
" quit : disconnect\n"
|
" quit : disconnect\n"
|
||||||
" show env [var] : dump environment variables known to the process\n"
|
" show env [var] : dump environment variables known to the process\n"
|
||||||
" show info : report information about the running 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 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"
|
" 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"
|
" 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;
|
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) {
|
else if (strcmp(args[1], "info") == 0) {
|
||||||
if (strcmp(args[2], "typed") == 0)
|
if (strcmp(args[2], "typed") == 0)
|
||||||
appctx->ctx.stats.flags |= STAT_FMT_TYPED;
|
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))
|
if (stats_dump_info_to_buffer(si))
|
||||||
appctx->st0 = STAT_CLI_PROMPT;
|
appctx->st0 = STAT_CLI_PROMPT;
|
||||||
break;
|
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 */
|
case STAT_CLI_O_ERR: /* errors dump */
|
||||||
if (stats_dump_errors_to_buffer(si))
|
if (stats_dump_errors_to_buffer(si))
|
||||||
appctx->st0 = STAT_CLI_PROMPT;
|
appctx->st0 = STAT_CLI_PROMPT;
|
||||||
|
41
src/stats.c
41
src/stats.c
@ -38,6 +38,7 @@
|
|||||||
#include <common/base64.h>
|
#include <common/base64.h>
|
||||||
|
|
||||||
#include <types/applet.h>
|
#include <types/applet.h>
|
||||||
|
#include <types/cli.h>
|
||||||
#include <types/global.h>
|
#include <types/global.h>
|
||||||
#include <types/dns.h>
|
#include <types/dns.h>
|
||||||
#include <types/stats.h>
|
#include <types/stats.h>
|
||||||
@ -45,6 +46,7 @@
|
|||||||
#include <proto/backend.h>
|
#include <proto/backend.h>
|
||||||
#include <proto/channel.h>
|
#include <proto/channel.h>
|
||||||
#include <proto/checks.h>
|
#include <proto/checks.h>
|
||||||
|
#include <proto/cli.h>
|
||||||
#include <proto/compression.h>
|
#include <proto/compression.h>
|
||||||
#include <proto/stats.h>
|
#include <proto/stats.h>
|
||||||
#include <proto/fd.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
|
* 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.
|
* 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 appctx *appctx = __objt_appctx(si->end);
|
||||||
struct channel *rep = si_ic(si);
|
struct channel *rep = si_ic(si);
|
||||||
@ -2811,6 +2813,37 @@ static void http_stats_io_handler(struct appctx *appctx)
|
|||||||
/* just to make gcc happy */ ;
|
/* 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 = {
|
struct applet http_stats_applet = {
|
||||||
.obj_type = OBJ_TYPE_APPLET,
|
.obj_type = OBJ_TYPE_APPLET,
|
||||||
.name = "<STATS>", /* used for logging */
|
.name = "<STATS>", /* used for logging */
|
||||||
@ -2818,6 +2851,12 @@ struct applet http_stats_applet = {
|
|||||||
.release = NULL,
|
.release = NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
__attribute__((constructor))
|
||||||
|
static void __stat_init(void)
|
||||||
|
{
|
||||||
|
cli_register_kw(&cli_kws);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Local variables:
|
* Local variables:
|
||||||
* c-indent-level: 8
|
* c-indent-level: 8
|
||||||
|
Loading…
x
Reference in New Issue
Block a user