mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 15:17:01 +02:00
MINOR: mworker: implement a reload failure counter
Implement a reload failure counter which counts the number of failure since the last success. This counter is available in 'show proc' over the master CLI.
This commit is contained in:
parent
ad221f4ece
commit
6883674084
@ -40,6 +40,7 @@ struct mworker_proc {
|
||||
char *version;
|
||||
int ipc_fd[2]; /* 0 is master side, 1 is worker side */
|
||||
int reloads;
|
||||
int failedreloads; /* number of failed reloads since the last successful one */
|
||||
int timestamp;
|
||||
struct server *srv; /* the server entry in the master proxy */
|
||||
struct list list;
|
||||
|
@ -864,8 +864,21 @@ static void mworker_loop()
|
||||
*/
|
||||
void reexec_on_failure()
|
||||
{
|
||||
struct mworker_proc *child;
|
||||
|
||||
if (!atexit_flag)
|
||||
return;
|
||||
|
||||
/* get the info of the children in the env */
|
||||
if (mworker_env_to_proc_list() < 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* increment the number of failed reloads */
|
||||
list_for_each_entry(child, &proc_list, list) {
|
||||
child->failedreloads++;
|
||||
}
|
||||
|
||||
usermsgs_clr(NULL);
|
||||
ha_warning("Loading failure!\n");
|
||||
mworker_reexec_waitmode();
|
||||
@ -1945,6 +1958,7 @@ static void init(int argc, char **argv)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
tmproc->options |= PROC_O_TYPE_MASTER; /* master */
|
||||
tmproc->failedreloads = 0;
|
||||
tmproc->reloads = 0;
|
||||
tmproc->pid = pid;
|
||||
tmproc->timestamp = start_date.tv_sec;
|
||||
@ -1964,6 +1978,7 @@ static void init(int argc, char **argv)
|
||||
|
||||
tmproc->options |= PROC_O_TYPE_WORKER; /* worker */
|
||||
tmproc->pid = -1;
|
||||
tmproc->failedreloads = 0;
|
||||
tmproc->reloads = 0;
|
||||
tmproc->timestamp = -1;
|
||||
tmproc->ipc_fd[0] = -1;
|
||||
@ -3268,6 +3283,7 @@ int main(int argc, char **argv)
|
||||
|
||||
/* if not in wait mode, reload in wait mode to free the memory */
|
||||
ha_notice("Loading success.\n");
|
||||
proc_self->failedreloads = 0; /* reset the number of failure */
|
||||
mworker_reexec_waitmode();
|
||||
}
|
||||
/* should never get there */
|
||||
|
@ -122,7 +122,7 @@ void mworker_proc_list_to_env()
|
||||
type = 'w';
|
||||
|
||||
if (child->pid > -1)
|
||||
memprintf(&msg, "%s|type=%c;fd=%d;pid=%d;reloads=%d;timestamp=%d;id=%s;version=%s", msg ? msg : "", type, child->ipc_fd[0], child->pid, child->reloads, child->timestamp, child->id ? child->id : "", child->version);
|
||||
memprintf(&msg, "%s|type=%c;fd=%d;pid=%d;reloads=%d;failedreloads=%d;timestamp=%d;id=%s;version=%s", msg ? msg : "", type, child->ipc_fd[0], child->pid, child->reloads, child->failedreloads, child->timestamp, child->id ? child->id : "", child->version);
|
||||
}
|
||||
if (msg)
|
||||
setenv("HAPROXY_PROCESSES", msg, 1);
|
||||
@ -176,6 +176,8 @@ int mworker_env_to_proc_list()
|
||||
} else if (strncmp(subtoken, "reloads=", 8) == 0) {
|
||||
/* we only increment the number of asked reload */
|
||||
child->reloads = atoi(subtoken+8);
|
||||
} else if (strncmp(subtoken, "failedreloads=", 14) == 0) {
|
||||
child->failedreloads = atoi(subtoken+14);
|
||||
} else if (strncmp(subtoken, "timestamp=", 10) == 0) {
|
||||
child->timestamp = atoi(subtoken+10);
|
||||
} else if (strncmp(subtoken, "id=", 3) == 0) {
|
||||
@ -455,15 +457,18 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
|
||||
int old = 0;
|
||||
int up = now.tv_sec - proc_self->timestamp;
|
||||
char *uptime = NULL;
|
||||
char *reloadtxt = NULL;
|
||||
|
||||
if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW)))
|
||||
return 1;
|
||||
|
||||
chunk_reset(&trash);
|
||||
|
||||
memprintf(&reloadtxt, "%d [failed: %d]", proc_self->reloads, proc_self->failedreloads);
|
||||
chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %-15s\n", "<PID>", "<type>", "<reloads>", "<uptime>", "<version>");
|
||||
memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
|
||||
chunk_appendf(&trash, "%-15u %-15s %-15d %-15s %-15s\n", (unsigned int)getpid(), "master", proc_self->reloads, uptime, haproxy_version);
|
||||
chunk_appendf(&trash, "%-15u %-15s %-15s %-15s %-15s\n", (unsigned int)getpid(), "master", reloadtxt, uptime, haproxy_version);
|
||||
ha_free(&reloadtxt);
|
||||
ha_free(&uptime);
|
||||
|
||||
/* displays current processes */
|
||||
|
Loading…
Reference in New Issue
Block a user