mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-02 10:12:03 +00:00
MINOR: cli: add an option to display the uptime in the CLI's prompt
Entering "prompt timed" toggles reporting of the process' uptime in the prompt, which will report days, hours, minutes and seconds since it was started. As discussed with Tim in issue #2145, this can be convenient to roughly estimate the time between two outputs, as well as detecting that a process failed to be reloaded for example.
This commit is contained in:
parent
21d7125c92
commit
225555711f
@ -1497,6 +1497,20 @@ For this reason, when debugging by hand, it's quite common to start with the
|
||||
...
|
||||
>
|
||||
|
||||
Optionally the process' uptime may be displayed in the prompt. In order to
|
||||
enable this, the "prompt timed" command will enable the prompt and toggle the
|
||||
displaying of the time. The uptime is displayed in format "d:hh:mm:ss" where
|
||||
"d" is the number of days, and "hh", "mm", "ss" are respectively the number
|
||||
of hours, minutes and seconds on two digits each:
|
||||
|
||||
# socat /var/run/haproxy readline
|
||||
prompt timed
|
||||
|
||||
[23:03:34:39]> show version
|
||||
2.8-dev9-e5e622-18
|
||||
|
||||
[23:03:34:41]> quit
|
||||
|
||||
Since multiple commands may be issued at once, haproxy uses the empty line as a
|
||||
delimiter to mark an end of output for each command, and takes care of ensuring
|
||||
that no command can emit an empty line on output. A script can thus easily
|
||||
|
@ -42,6 +42,7 @@
|
||||
#define APPCTX_CLI_ST1_PROMPT (1 << 0)
|
||||
#define APPCTX_CLI_ST1_PAYLOAD (1 << 1)
|
||||
#define APPCTX_CLI_ST1_NOLF (1 << 2)
|
||||
#define APPCTX_CLI_ST1_TIMED (1 << 3)
|
||||
|
||||
#define CLI_PREFIX_KW_NB 5
|
||||
#define CLI_MAX_MATCHES 5
|
||||
|
17
src/cli.c
17
src/cli.c
@ -319,7 +319,7 @@ static char *cli_gen_usage_msg(struct appctx *appctx, char * const *args)
|
||||
/* always show the prompt/help/quit commands */
|
||||
chunk_strcat(tmp,
|
||||
" help [<command>] : list matching or all commands\n"
|
||||
" prompt : toggle interactive mode with prompt\n"
|
||||
" prompt [timed] : toggle interactive mode with prompt\n"
|
||||
" quit : disconnect\n");
|
||||
|
||||
chunk_init(&out, NULL, 0);
|
||||
@ -1115,6 +1115,7 @@ static void cli_io_handler(struct appctx *appctx)
|
||||
|
||||
/* The post-command prompt is either LF alone or LF + '> ' in interactive mode */
|
||||
if (appctx->st0 == CLI_ST_PROMPT) {
|
||||
char prompt_buf[20];
|
||||
const char *prompt = "";
|
||||
|
||||
if (appctx->st1 & APPCTX_CLI_ST1_PROMPT) {
|
||||
@ -1124,6 +1125,13 @@ static void cli_io_handler(struct appctx *appctx)
|
||||
*/
|
||||
if (appctx->chunk->data && appctx->st1 & APPCTX_CLI_ST1_PAYLOAD)
|
||||
prompt = "+ ";
|
||||
else if (appctx->st1 & APPCTX_CLI_ST1_TIMED) {
|
||||
uint up = ns_to_sec(now_ns - start_time_ns);
|
||||
snprintf(prompt_buf, sizeof(prompt_buf),
|
||||
"\n[%u:%02u:%02u:%02u]> ",
|
||||
(up / 86400), (up / 3600) % 24, (up / 60) % 60, up % 60);
|
||||
prompt = prompt_buf;
|
||||
}
|
||||
else
|
||||
prompt = "\n> ";
|
||||
}
|
||||
@ -2187,7 +2195,12 @@ static int cli_parse_simple(char **args, char *payload, struct appctx *appctx, v
|
||||
cli_gen_usage_msg(appctx, args);
|
||||
else if (*args[0] == 'p')
|
||||
/* prompt */
|
||||
appctx->st1 ^= APPCTX_CLI_ST1_PROMPT;
|
||||
if (strcmp(args[1], "timed") == 0) {
|
||||
appctx->st1 |= APPCTX_CLI_ST1_PROMPT;
|
||||
appctx->st1 ^= APPCTX_CLI_ST1_TIMED;
|
||||
}
|
||||
else
|
||||
appctx->st1 ^= APPCTX_CLI_ST1_PROMPT;
|
||||
else if (*args[0] == 'q') {
|
||||
/* quit */
|
||||
se_fl_set(appctx->sedesc, SE_FL_EOI);
|
||||
|
Loading…
Reference in New Issue
Block a user