MINOR: cli: displays uptime in `show proc`
Displays the uptime of the workers in `show proc`
diff --git a/include/types/global.h b/include/types/global.h
index 5210323..be4d7c5 100644
--- a/include/types/global.h
+++ b/include/types/global.h
@@ -212,6 +212,7 @@
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 3d3abb8..24cb2a4 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -1405,19 +1405,20 @@
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 @@
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 93d6aa3..276652b 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -541,9 +541,9 @@
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 @@
} 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 @@
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 @@
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;
}