[MEDIUM] stats: split frontend and backend stats

It's very annoying that frontend and backend stats are merged because we
don't know what we're observing. For instance, if a "listen" instance
makes use of a distinct backend, it's impossible to know what the bytes_out
means.

Some points take care of not updating counters twice if the backend points
to the frontend, indicating a "listen" instance. The thing becomes more
complex when we try to add support for server side keep-alive, because we
have to maintain a pointer to the backend used for last request, and to
update its stats. But we can't perform such comparisons anymore because
the counters will not match anymore.

So in order to get rid of this situation, let's have both frontend AND
backend stats in the "struct proxy". We simply update the relevant ones
during activity. Some of them are only accounted for in the backend,
while others are just for frontend. Maybe we can improve a bit on that
later, but the essential part is that those counters now reflect what
they really mean.
diff --git a/include/types/counters.h b/include/types/counters.h
index a333219..e3e051f 100644
--- a/include/types/counters.h
+++ b/include/types/counters.h
@@ -1,56 +1,61 @@
 /*
-  include/types/counters.h
-  This file contains structure declarations for statistics counters.
-
-  Copyright 2008-2009 Krzysztof Piotr Oledzki <ole@ans.pl>
-
-  This library is free software; you can redistribute it and/or
-  modify it under the terms of the GNU Lesser General Public
-  License as published by the Free Software Foundation, version 2.1
-  exclusively.
-
-  This library is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public
-  License along with this library; if not, write to the Free Software
-  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-*/
+ * include/types/counters.h
+ * This file contains structure declarations for statistics counters.
+ *
+ * Copyright 2008-2009 Krzysztof Piotr Oledzki <ole@ans.pl>
+ * Copyright 2011 Willy Tarreau <w@1wt.eu>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, version 2.1
+ * exclusively.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
 
 #ifndef _TYPES_COUNTERS_H
 #define _TYPES_COUNTERS_H
 
+/* maybe later we might thing about having a different struct for FE and BE */
 struct pxcounters {
-	unsigned int feconn_max, beconn_max;	/* max # of active frontend and backend sessions */
+	unsigned int conn_max;                  /* max # of active sessions */
+	long long    cum_conn;                  /* cumulated number of received connections */
+	long long    cum_sess;                  /* cumulated number of accepted connections */
+	long long  cum_lbconn;                  /* cumulated number of sessions processed by load balancing (BE only) */
 
-	long long cum_fe_req;			/* cumulated number of processed HTTP requests */
-	long long cum_feconn, cum_fesess;	/* cumulated number of received/accepted connections */
-	long long cum_beconn, cum_lbconn;	/* cumulated number of sessions processed by load balancing */
+	unsigned int cps_max;                   /* maximum of new connections received per second */
+	unsigned int sps_max;                   /* maximum of new connections accepted per second (sessions) */
+	unsigned int nbpend_max;                /* max number of pending connections with no server assigned yet (BE only) */
 
-	unsigned int fe_rps_max;		/* maximum of new sessions per second seen on the frontend */
-	unsigned int fe_cps_max;		/* maximum of new connections per second received on the frontend */
-	unsigned int fe_sps_max;		/* maximum of new sessions per second accepted on the frontend */
-	unsigned int be_sps_max;		/* maximum of new sessions per second seen on the backend */
-	unsigned int nbpend_max;		/* max number of pending connections with no server assigned yet */
+	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 */
 
-	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 */
+	long long denied_req;                   /* blocked requests/responses because of security concerns */
+	long long denied_resp;                  /* blocked requests/responses because of security concerns */
+	long long failed_req;                   /* failed requests (eg: invalid or timeout) */
+	long long denied_conn;                  /* denied connection requests (tcp-req rules) */
 
-	long long denied_req, denied_resp;	/* blocked requests/responses because of security concerns */
-	long long failed_req;			/* failed requests (eg: invalid or timeout) */
-	long long denied_conn;			/* denied connection requests (tcp-req rules) */
+	long long failed_conns;                 /* failed connect() attempts (BE only) */
+	long long failed_resp;                  /* failed responses (BE only) */
+	long long cli_aborts;                   /* aborted responses during DATA phase caused by the client */
+	long long srv_aborts;                   /* aborted responses during DATA phase caused by the server */
+	long long retries;                      /* retried and redispatched connections (BE only) */
+	long long redispatches;                 /* retried and redispatched connections (BE only) */
 
 	union {
 		struct {
-			long long rsp[6];	/* http response codes */
+			long long cum_req;      /* cumulated number of processed HTTP requests */
+			unsigned int rps_max;   /* maximum of new HTTP requests second observed */
+			long long rsp[6];       /* http response codes */
 		} http;
-	} fe, be;				/* FE and BE stats */
-
-	long long failed_conns, failed_resp;	/* failed connect() and responses */
-	long long cli_aborts, srv_aborts;	/* aborted responses during DATA phase due to client or server */
-	long long retries, redispatches;	/* retried and redispatched connections */
+	} p;                                    /* protocol-specific stats */
 };
 
 struct licounters {
diff --git a/include/types/proxy.h b/include/types/proxy.h
index 95736b1..6208d7b 100644
--- a/include/types/proxy.h
+++ b/include/types/proxy.h
@@ -297,7 +297,8 @@
 	                 *rsp_cap_pool;
 	struct pool_head *hdr_idx_pool;         /* pools of pre-allocated int* used for headers indexing */
 	struct list req_add, rsp_add;           /* headers to be added */
-	struct pxcounters counters;		/* statistics counters */
+	struct pxcounters be_counters;		/* backend statistics counters */
+	struct pxcounters fe_counters;		/* frontend statistics counters */
 
 	struct stktable table;			/* table for storing sticking sessions */