Displays the uptime of the workers in `show proc`
---
include/types/global.h | 1 +
src/cli.c | 10 ++++++----
src/haproxy.c | 8 ++++++--
3 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/include/types/global.h b/include/types/global.h
index 521032304..be4d7c533 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -212,6 +212,7 @@ struct mworker_proc {
int ipc_fd[2]; /* 0 is master side, 1 is worker side */
int relative_pid;
int reloads;
+ int timestamp;
struct server *srv; /* the server entry in the master proxy */
struct list list;
};
diff --git a/src/cli.c b/src/cli.c
index 3d3abb893..24cb2a48f 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -1405,19 +1405,20 @@ static int cli_io_handler_show_proc(struct appctx
*appctx)
chunk_reset(&trash);
- chunk_printf(&trash, "#%-14s %-15s %-15s %-15s\n", "<PID>", "<type>",
"<relative PID>", "<reloads>");
- chunk_appendf(&trash, "%-15u %-15s %-15u %-15s\n", getpid(), "master",
0, "-");
+ chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %s\n", "<PID>",
"<type>", "<relative PID>", "<reloads>", "<uptime>");
+ chunk_appendf(&trash, "%-15u %-15s %-15u %-15s %s\n", getpid(),
"master", 0, "-", "-");
/* displays current processes */
chunk_appendf(&trash, "# workers\n");
list_for_each_entry(child, &proc_list, list) {
+ int up = now.tv_sec - child->timestamp;
if (child->reloads > 0) {
old++;
continue;
}
- chunk_appendf(&trash, "%-15u %-15s %-15u %-15d\n", child->pid,
"worker", child->relative_pid, child->reloads);
+ chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %dd
%02dh%02dm%02ds\n", child->pid, "worker", child->relative_pid, child->reloads,
up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
}
/* displays old processes */
@@ -1425,8 +1426,9 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
if (old) {
chunk_appendf(&trash, "# old workers\n");
list_for_each_entry(child, &proc_list, list) {
+ int up = now.tv_sec - child->timestamp;
if (child->reloads > 0)
- chunk_appendf(&trash, "%-15u %-15s %-15u
%-15d\n", child->pid, "worker", child->relative_pid, child->reloads);
+ chunk_appendf(&trash, "%-15u %-15s %-15u %-15d
%dd %02dh%02dm%02ds\n", child->pid, "worker", child->relative_pid,
child->reloads, up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
}
}
diff --git a/src/haproxy.c b/src/haproxy.c
index 93d6aa373..276652b99 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -541,9 +541,9 @@ static void mworker_proc_list_to_env()
list_for_each_entry(child, &proc_list, list) {
if (msg)
- memprintf(&msg,
"%s|type=worker;fd=%d;pid=%d;rpid=%d;reloads=%d", msg, child->ipc_fd[0],
child->pid, child->relative_pid, child->reloads);
+ memprintf(&msg,
"%s|type=worker;fd=%d;pid=%d;rpid=%d;reloads=%d;timestamp=%d", msg,
child->ipc_fd[0], child->pid, child->relative_pid, child->reloads,
child->timestamp);
else
- memprintf(&msg,
"type=worker;fd=%d;pid=%d;rpid=%d;reloads=%d", child->ipc_fd[0], child->pid,
child->relative_pid, child->reloads);
+ memprintf(&msg,
"type=worker;fd=%d;pid=%d;rpid=%d;reloads=%d;timestamp=%d", child->ipc_fd[0],
child->pid, child->relative_pid, child->reloads, child->timestamp);
}
if (msg)
setenv("HAPROXY_CHILDREN", msg, 1);
@@ -582,6 +582,8 @@ static void mworker_env_to_proc_list()
} else if (strncmp(subtoken, "reloads=", 8) == 0) {
/* we reloaded this process once more */
child->reloads = atoi(subtoken+8) + 1;
+ } else if (strncmp(subtoken, "timestamp=", 10) == 0) {
+ child->timestamp = atoi(subtoken+10);
}
}
if (child->pid)
@@ -1745,6 +1747,7 @@ static void init(int argc, char **argv)
tmproc->pid = -1;
tmproc->reloads = 0;
+ tmproc->timestamp = -1;
tmproc->relative_pid = 1 + proc;
tmproc->ipc_fd[0] = -1;
tmproc->ipc_fd[1] = -1;
@@ -3018,6 +3021,7 @@ int main(int argc, char **argv)
list_for_each_entry(child, &proc_list, list) {
if (child->relative_pid == relative_pid
&&
child->reloads == 0) {
+ child->timestamp = now.tv_sec;
child->pid = ret;
break;
}
--
2.18.1