]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cli: displays uptime in `show proc`
authorWilliam Lallemand <wlallemand@haproxy.com>
Mon, 19 Nov 2018 17:46:17 +0000 (18:46 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 20 Nov 2018 03:43:54 +0000 (04:43 +0100)
Displays the uptime of the workers in `show proc`

include/types/global.h
src/cli.c
src/haproxy.c

index 5210323048c83251e67025d728eafe965f119c37..be4d7c5338ee5ceb048067faefb3304308459945 100644 (file)
@@ -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;
 };
index 3d3abb893d5d0ffaa9e6a8aaa832c5cd1a8ccd70..24cb2a48f789124c724a8abf3ca9f4cf63274ba8 100644 (file)
--- 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));
                }
        }
 
index 93d6aa373818f893c547ac01efc777809df4efa0..276652b9941be6db28f854cde0d6b23083534d02 100644 (file)
@@ -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;
                                        }