From: Willy Tarreau Date: Sun, 4 Nov 2007 22:35:08 +0000 (+0100) Subject: [MINOR] stats: report numerical process ID, proxy ID and server ID X-Git-Tag: v1.3.14~49 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dcd4771b3d462cfeba17c503d29a81698fd162df;p=thirdparty%2Fhaproxy.git [MINOR] stats: report numerical process ID, proxy ID and server ID 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. --- diff --git a/include/types/global.h b/include/types/global.h index bed62d894e..56c94c4cd2 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -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]; diff --git a/include/types/proxy.h b/include/types/proxy.h index bb8b872f68..ecc4d9c63c 100644 --- a/include/types/proxy.h +++ b/include/types/proxy.h @@ -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 */ diff --git a/include/types/server.h b/include/types/server.h index 6e3a9138b4..3553fc099e 100644 --- a/include/types/server.h +++ b/include/types/server.h @@ -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 */ }; diff --git a/src/cfgparse.c b/src/cfgparse.c index aaafe8cfba..9e895c4893 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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; diff --git a/src/dumpstats.c b/src/dumpstats.c index 7126de9c03..b38cd6c239 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -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; diff --git a/src/haproxy.c b/src/haproxy.c index eaf491ecb9..bff2142270 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -110,6 +110,7 @@ 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) diff --git a/src/proxy.c b/src/proxy.c index 1c7cff6e89..640a2c1d82 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -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