]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] stats: report numerical process ID, proxy ID and server ID
authorWilly Tarreau <w@1wt.eu>
Sun, 4 Nov 2007 22:35:08 +0000 (23:35 +0100)
committerWilly Tarreau <w@1wt.eu>
Sun, 4 Nov 2007 22:35:08 +0000 (23:35 +0100)
It is very convenient for SNMP monitoring to have unique process ID,
proxy ID and server ID. Those have been added to the CSV outputs.
The numbers start at 1. 0 is reserved. For servers, 0 means that the
reported name is not a server name but half a proxy (FRONTEND/BACKEND).

A remaining hidden "-" in the CSV output has been eliminated too.

include/types/global.h
include/types/proxy.h
include/types/server.h
src/cfgparse.c
src/dumpstats.c
src/haproxy.c
src/proxy.c

index bed62d894ec61c18c1fa068c0be82d4cd517e018..56c94c4cd2f7f0a5deb7a0252884aecb2ce967f1 100644 (file)
@@ -70,6 +70,7 @@ struct global {
 extern struct global global;
 extern char *progname;          /* program name */
 extern int  pid;                /* current process id */
+extern int  relative_pid;       /* process id starting at 1 */
 extern int  actconn;            /* # of active sessions */
 extern int listeners;
 extern char trash[BUFSIZE];
index bb8b872f68c1e31cbdaab8f0c64655a6ea26449f..ecc4d9c63c0d92541c360079ad9dcab1facab2a8 100644 (file)
@@ -150,6 +150,8 @@ struct proxy {
        char *check_req;                        /* HTTP or SSL request to use for PR_O_HTTP_CHK|PR_O_SSL3_CHK */
        int check_len;                          /* Length of the HTTP or SSL3 request */
        struct chunk errmsg[HTTP_ERR_SIZE];     /* default or customized error messages for known errors */
+       int uuid;                               /* universally unique proxy ID, used for SNMP */
+       int next_svid;                          /* next server-id, used for SNMP */
 };
 
 struct switching_rule {
@@ -162,6 +164,7 @@ struct switching_rule {
 };
 
 extern struct proxy *proxy;
+extern int next_pxid;
 
 #endif /* _TYPES_PROXY_H */
 
index 6e3a9138b450569e5f1a551bd52faddd4a253cf8..3553fc099ecec0eab76acb5f0d28a8947ebc0dd8 100644 (file)
@@ -97,6 +97,7 @@ struct server {
 
        long long bytes_in;                     /* number of bytes transferred from the client to the server */
        long long bytes_out;                    /* number of bytes transferred from the server to the client */
+       int puid;                               /* proxy-unique server ID, used for SNMP */
 };
 
 
index aaafe8cfbab0bb05fbda166b6fe1633a479c3e58..9e895c4893645916391c503e952c9886fc5166f5 100644 (file)
@@ -652,6 +652,8 @@ int cfg_parse_listen(const char *file, int linenum, char **args)
                curproxy->logsrv2 = defproxy.logsrv2;
                curproxy->loglev2 = defproxy.loglev2;
                curproxy->grace  = defproxy.grace;
+               curproxy->uuid = next_pxid++;   /* generate a uuid for this proxy */
+               curproxy->next_svid = 1;        /* server id 0 is reserved */
 
                return 0;
        }
@@ -1372,6 +1374,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args)
                newsrv->next = curproxy->srv;
                curproxy->srv = newsrv;
                newsrv->proxy = curproxy;
+               newsrv->puid = curproxy->next_svid++;
 
                LIST_INIT(&newsrv->pendconns);
                do_check = 0;
index 7126de9c035fc41ed94ea88b2b63e5c2891d892a..b38cd6c2399240fc4b92733e10d136bc3461deca 100644 (file)
@@ -374,6 +374,7 @@ int stats_dump_http(struct session *s, struct uri_auth *uri, int flags)
                             "wretr,wredis,"
                             "status,weight,act,bck,"
                             "chkfail,chkdown,lastchg,downtime,qlimit,"
+                            "pid,iid,sid,"
                             "\n");
                }
                if (buffer_write_chunk(rep, &msg) != 0)
@@ -659,6 +660,8 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri,
                                     "%s,"
                                     /* rest of server: nothing */
                                     ",,,,,,,,"
+                                    /* pid, iid, sid, */
+                                    "%d,%d,0,"
                                     "\n",
                                     px->id,
                                     px->feconn, px->feconn_max, px->maxconn, px->cum_feconn,
@@ -666,7 +669,8 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri,
                                     px->denied_req, px->denied_resp,
                                     px->failed_req,
                                     px->state == PR_STRUN ? "OPEN" :
-                                    px->state == PR_STIDLE ? "FULL" : "STOP");
+                                    px->state == PR_STIDLE ? "FULL" : "STOP",
+                                    relative_pid, px->uuid);
                        }
 
                        if (buffer_write_chunk(rep, &msg) != 0)
@@ -787,7 +791,7 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri,
                                     "",
                                     px->id, sv->id,
                                     sv->nbpend, sv->nbpend_max,
-                                    sv->cur_sess, sv->cur_sess_max, sv->maxconn ? ultoa(sv->maxconn) : "-", sv->cum_sess,
+                                    sv->cur_sess, sv->cur_sess_max, LIM2A0(sv->maxconn, ""), sv->cum_sess,
                                     sv->bytes_in, sv->bytes_out,
                                     sv->failed_secu,
                                     sv->failed_conns, sv->failed_resp,
@@ -817,10 +821,13 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri,
                                        chunk_printf(&msg, sizeof(trash),
                                             ",,,,");
 
-                               /* queue limit and EOL */
+                               /* queue limit, pid, iid, sid and EOL */
                                chunk_printf(&msg, sizeof(trash),
-                                    "%s,\n",
-                                    LIM2A0(sv->maxqueue, ""));
+                                    "%s,"
+                                    "%d,%d,%d,"
+                                    "\n",
+                                    LIM2A0(sv->maxqueue, ""),
+                                    relative_pid, px->uuid, sv->puid);
                        }
                        if (buffer_write_chunk(rep, &msg) != 0)
                                return 0;
@@ -910,6 +917,8 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri,
                                     /* rest of backend: nothing, down transformations,
                                      * last change, total downtime. */
                                     ",%d,%d,%d,,"
+                                    /* pid, iid, sid, */
+                                    "%d,%d,0,"
                                     "\n",
                                     px->id,
                                     px->nbpend /* or px->totpend ? */, px->nbpend_max,
@@ -921,7 +930,8 @@ int stats_dump_proxy(struct session *s, struct proxy *px, struct uri_auth *uri,
                                     (px->srv_map_sz > 0 || !px->srv) ? "UP" : "DOWN",
                                     px->srv_map_sz * gcd, px->srv_act, px->srv_bck,
                                     px->down_trans, now.tv_sec - px->last_change,
-                                    px->srv?be_downtime(px):0);
+                                            px->srv?be_downtime(px):0,
+                                    relative_pid, px->uuid);
                        }
                        if (buffer_write_chunk(rep, &msg) != 0)
                                return 0;
index eaf491ecb91de4f9762abc064b1ea73b388a9e27..bff21422704ca227bbd34ab70bd5b168028d5dc1 100644 (file)
 char *cfg_cfgfile = NULL;      /* configuration file */
 char *progname = NULL;         /* program name */
 int  pid;                      /* current process id */
+int  relative_pid;             /* process id starting at 1 */
 
 /* global options */
 struct global global = {
@@ -1014,6 +1015,7 @@ int main(int argc, char **argv)
                                fprintf(pidfile, "%d\n", ret);
                                fflush(pidfile);
                        }
+                       relative_pid++; /* each child will get a different one */
                }
                /* close the pidfile both in children and father */
                if (pidfile != NULL)
index 1c7cff6e8935e2896adfdb84eb8f302e63a534e1..640a2c1d82fb3df265d8e4af38bcf9fb1e8bed73 100644 (file)
@@ -37,6 +37,7 @@
 
 int listeners; /* # of proxy listeners, set by cfgparse, unset by maintain_proxies */
 struct proxy *proxy  = NULL;   /* list of all existing proxies */
+int next_pxid = 1;             /* UUID assigned to next new proxy, 0 reserved */
 
 /*
  * This function returns a string containing a name describing capabilities to