]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[STATS] add support for "show info" on the unix socket
authorWilly Tarreau <w@1wt.eu>
Thu, 3 Jan 2008 09:19:15 +0000 (10:19 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 3 Jan 2008 09:19:15 +0000 (10:19 +0100)
It is sometimes required to know some informations such as the
process uptime when consulting statistics. This patch adds the
"show info" command to query those informations on the UNIX
socket.

doc/configuration.txt
include/proto/dumpstats.h
src/dumpstats.c
src/proto_uxst.c

index 350eab501fb443ed2933d3c51d2dd2eb73394c56..4cc89d4b40f030ce6912de07a91524e98e58d0f5 100644 (file)
@@ -145,14 +145,16 @@ stats socket <path> [{uid | user} <uid>] [{gid | group} <gid>] [mode <mode>]
   Creates a UNIX socket in stream mode at location <path>. Any previously
   existing socket will be backed up then replaced. Connections to this socket
   will get a CSV-formated output of the process statistics in response to the
-  "show stat" command followed by a line feed. On platforms which support it,
-  it is possible to restrict access to this socket by specifying numerical IDs
-  after "uid" and "gid", or valid user and group names after the "user" and
-  "group" keywords. It is also possible to restrict permissions on the socket
-  by passing an octal value after the "mode" keyword (same syntax as chmod).
-  Depending on the platform, the permissions on the socket will be inherited
-  from the directory which hosts it, or from the user the process is started
-  with.
+  "show stat" command followed by a line feed, and more general process
+  information in response to the "show info" command followed by a line feed.
+
+  On platforms which support it, it is possible to restrict access to this
+  socket by specifying numerical IDs after "uid" and "gid", or valid user and
+  group names after the "user" and "group" keywords. It is also possible to
+  restrict permissions on the socket by passing an octal value after the "mode"
+  keyword (same syntax as chmod). Depending on the platform, the permissions on
+  the socket will be inherited from the directory which hosts it, or from the
+  user the process is started with.
 
 stats timeout <timeout, in milliseconds>
   The default timeout on the stats socket is set to 10 seconds. It is possible
index efe5fa919a55226454a706e9c19b99bd5126ece2..198f0d793492ccac7ba8b58b1dd99302684bb0cf 100644 (file)
@@ -27,7 +27,9 @@
 #include <types/buffers.h>
 #include <types/session.h>
 
-#define STAT_FMT_HTML 0x1
+#define STAT_FMT_HTML  0x1
+#define STAT_SHOW_STAT 0x2
+#define STAT_SHOW_INFO 0x4
 
 int stats_parse_global(const char **args, char *err, int errlen);
 int stats_dump_raw(struct session *s, struct uri_auth *uri, int flags);
index f7522719c35223dede7e8d50fa36de7f54ba582c..a0e80dfab8e955d78997c60b03272f66636a2d24 100644 (file)
@@ -187,6 +187,7 @@ int stats_dump_raw(struct session *s, struct uri_auth *uri, int flags)
        struct buffer *rep = s->rep;
        struct proxy *px;
        struct chunk msg;
+       unsigned int up;
 
        msg.len = 0;
        msg.str = trash;
@@ -201,16 +202,50 @@ int stats_dump_raw(struct session *s, struct uri_auth *uri, int flags)
                /* fall through */
 
        case DATA_ST_HEAD:
-               print_csv_header(&msg, sizeof(trash));
-               if (buffer_write_chunk(rep, &msg) != 0)
-                       return 0;
+               if (flags & STAT_SHOW_STAT) {
+                       print_csv_header(&msg, sizeof(trash));
+                       if (buffer_write_chunk(rep, &msg) != 0)
+                               return 0;
+               }
 
                s->data_state = DATA_ST_INFO;
                /* fall through */
 
        case DATA_ST_INFO:
+               up = (now.tv_sec - start_date.tv_sec);
                memset(&s->data_ctx, 0, sizeof(s->data_ctx));
 
+               if (flags & STAT_SHOW_INFO) {
+                       chunk_printf(&msg, sizeof(trash),
+                                    "Name: " PRODUCT_NAME "\n"
+                                    "Version: " HAPROXY_VERSION "\n"
+                                    "Release_date: " HAPROXY_DATE "\n"
+                                    "Nbproc: %d\n"
+                                    "Process_num: %d\n"
+                                    "Pid: %d\n"
+                                    "Uptime: %dd %dh%02dm%02ds\n"
+                                    "Uptime_sec: %d\n"
+                                    "Memmax_MB: %d\n"
+                                    "Ulimit-n: %d\n"
+                                    "Maxsock: %d\n"
+                                    "Maxconn: %d\n"
+                                    "CurrConns: %d\n"
+                                    "",
+                                    global.nbproc,
+                                    relative_pid,
+                                    pid,
+                                    up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60),
+                                    up,
+                                    global.rlimit_memmax,
+                                    global.rlimit_nofile,
+                                    global.maxsock,
+                                    global.maxconn,
+                                    actconn
+                                    );
+                       if (buffer_write_chunk(rep, &msg) != 0)
+                               return 0;
+               }
+
                s->data_ctx.stats.px = proxy;
                s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
                s->data_state = DATA_ST_LIST;
@@ -218,17 +253,20 @@ int stats_dump_raw(struct session *s, struct uri_auth *uri, int flags)
 
        case DATA_ST_LIST:
                /* dump proxies */
-               while (s->data_ctx.stats.px) {
-                       px = s->data_ctx.stats.px;
-                       /* skip the disabled proxies and non-networked ones */
-                       if (px->state != PR_STSTOPPED && (px->cap & (PR_CAP_FE | PR_CAP_BE)))
-                               if (stats_dump_proxy(s, px, NULL, 0) == 0)
-                                       return 0;
-
-                       s->data_ctx.stats.px = px->next;
-                       s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
+               if (flags & STAT_SHOW_STAT) {
+                       while (s->data_ctx.stats.px) {
+                               px = s->data_ctx.stats.px;
+                               /* skip the disabled proxies and non-networked ones */
+                               if (px->state != PR_STSTOPPED &&
+                                   (px->cap & (PR_CAP_FE | PR_CAP_BE)))
+                                       if (stats_dump_proxy(s, px, NULL, 0) == 0)
+                                               return 0;
+
+                               s->data_ctx.stats.px = px->next;
+                               s->data_ctx.stats.px_st = DATA_ST_PX_INIT;
+                       }
+                       /* here, we just have reached the last proxy */
                }
-               /* here, we just have reached the last proxy */
 
                s->data_state = DATA_ST_END;
                /* fall through */
@@ -402,7 +440,7 @@ int stats_dump_http(struct session *s, struct uri_auth *uri, int flags)
                             "<hr width=\"100%%\" class=\"hr\">\n"
                             "<h3>&gt; General process information</h3>\n"
                             "<table border=0 cols=4><tr><td align=\"left\" nowrap width=\"1%%\">\n"
-                            "<p><b>pid = </b> %d (nbproc = %d)<br>\n"
+                            "<p><b>pid = </b> %d (process #%d, nbproc = %d)<br>\n"
                             "<b>uptime = </b> %dd %dh%02dm%02ds<br>\n"
                             "<b>system limits :</b> memmax = %s%s ; ulimit-n = %d<br>\n"
                             "<b>maxsock = </b> %d<br>\n"
@@ -427,7 +465,8 @@ int stats_dump_http(struct session *s, struct uri_auth *uri, int flags)
                             "<b>Display option:</b><ul style=\"margin-top: 0.25em;\">"
                             "",
                             (uri->flags&ST_HIDEVER)?"":(STATS_VERSION_STRING),
-                            pid, pid, global.nbproc,
+                            pid, pid,
+                            relative_pid, global.nbproc,
                             up / 86400, (up % 86400) / 3600,
                             (up % 3600) / 60, (up % 60),
                             global.rlimit_memmax ? ultoa(global.rlimit_memmax) : "unlimited",
index ca7e1e3c14eb57bdff96458da0e94f1fb0996fe9..d367e2bca9908704219e8a1ed533a49f7a9d184e 100644 (file)
@@ -1386,7 +1386,15 @@ void process_uxst_stats(struct task *t, struct timeval *next)
                if (s->data_state == DATA_ST_INIT) {
                        if ((s->req->l >= 10) && (memcmp(s->req->data, "show stat\n", 10) == 0)) {
                                /* send the stats, and changes the data_state */
-                               if (stats_dump_raw(s, NULL, 0) != 0) {
+                               if (stats_dump_raw(s, NULL, STAT_SHOW_STAT) != 0) {
+                                       s->srv_state = SV_STCLOSE;
+                                       fsm_resync |= 1;
+                                       continue;
+                               }
+                       }
+                       if ((s->req->l >= 10) && (memcmp(s->req->data, "show info\n", 10) == 0)) {
+                               /* send the stats, and changes the data_state */
+                               if (stats_dump_raw(s, NULL, STAT_SHOW_INFO) != 0) {
                                        s->srv_state = SV_STCLOSE;
                                        fsm_resync |= 1;
                                        continue;