[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.
This commit is contained in:
Willy Tarreau 2007-11-04 23:35:08 +01:00
parent e6b989479c
commit dcd4771b3d
7 changed files with 27 additions and 6 deletions

View 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];

View 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 */

View 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 */
};

View 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;

View 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;

View File

@ -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)

View 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