MINOR: contrib/prometheus-exporter: Report metrics about max times for sessions

Now, for the sessions, the maximum times (queue, connect, response, total) are
reported in addition of the averages over the last 1024 connections. These
metrics are reported per backend and per server. Here are the metrics name :

  * haproxy_backend_max_queue_time_seconds
  * haproxy_backend_max_connect_time_seconds
  * haproxy_backend_max_response_time_seconds
  * haproxy_backend_max_total_time_seconds

and

  * haproxy_server_max_queue_time_seconds
  * haproxy_server_max_connect_time_seconds
  * haproxy_server_max_response_time_seconds
  * haproxy_server_max_total_time_seconds

This patch is related to #272.

(cherry picked from commit 8fc027d4685afc9f3a1bea77162ff91b94407932)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/contrib/prometheus-exporter/README b/contrib/prometheus-exporter/README
index d33e194..6467ffe 100644
--- a/contrib/prometheus-exporter/README
+++ b/contrib/prometheus-exporter/README
@@ -170,6 +170,10 @@
 | haproxy_backend_http_connect_time_average_seconds   | Avg. connect time for last 1024 successful connections.                  |
 | haproxy_backend_http_response_time_average_seconds  | Avg. response time for last 1024 successful connections.                 |
 | haproxy_backend_http_total_time_average_seconds     | Avg. total time for last 1024 successful connections.                    |
+| haproxy_backend_max_queue_time_seconds              | Maximum observed queue time.                                             |
+| haproxy_backend_max_connect_time_seconds            | Maximum observed connect time.                                           |
+| haproxy_backend_max_response_time_seconds           | Maximum observed response time.                                          |
+| haproxy_backend_max_total_time_seconds              | Maximum observed total time.                                             |
 | haproxy_backend_requests_denied_total               | Total number of denied requests.                                         |
 | haproxy_backend_responses_denied_total              | Total number of denied responses.                                        |
 | haproxy_backend_connection_errors_total             | Total number of connection errors.                                       |
@@ -217,6 +221,10 @@
 | haproxy_server_http_connect_time_average_seconds   | Avg. connect time for last 1024 successful connections.                   |
 | haproxy_server_http_response_time_average_seconds  | Avg. response time for last 1024 successful connections.                  |
 | haproxy_server_http_total_time_average_seconds     | Avg. total time for last 1024 successful connections.                     |
+| haproxy_server_max_queue_time_seconds              | Maximum observed queue time.                                              |
+| haproxy_server_max_connect_time_seconds            | Maximum observed connect time.                                            |
+| haproxy_server_max_response_time_seconds           | Maximum observed response time.                                           |
+| haproxy_server_max_total_time_seconds              | Maximum observed total time.                                              |
 | haproxy_server_connection_attempts_total           | Total number of connection establishment attempts.                        |
 | haproxy_server_connection_reuses_total             | Total number of connection reuses.                                        |
 | haproxy_server_responses_denied_total              | Total number of denied responses.                                         |
diff --git a/contrib/prometheus-exporter/service-prometheus.c b/contrib/prometheus-exporter/service-prometheus.c
index 3cf3a93..1991823 100644
--- a/contrib/prometheus-exporter/service-prometheus.c
+++ b/contrib/prometheus-exporter/service-prometheus.c
@@ -232,6 +232,10 @@
 	[ST_F_REUSE]          = 0,
 	[ST_F_CACHE_LOOKUPS]  = ST_F_CACHE_HITS,
 	[ST_F_CACHE_HITS]     = ST_F_COMP_IN,
+	[ST_F_QT_MAX]         = 0,
+	[ST_F_CT_MAX]         = 0,
+	[ST_F_RT_MAX]         = 0,
+	[ST_F_TT_MAX]         = 0,
 };
 
 /* Matrix used to dump backend metrics. Each metric points to the next one to be
@@ -298,7 +302,7 @@
 	[ST_F_QTIME]          = ST_F_CTIME,
 	[ST_F_CTIME]          = ST_F_RTIME,
 	[ST_F_RTIME]          = ST_F_TTIME,
-	[ST_F_TTIME]          = ST_F_DREQ,
+	[ST_F_TTIME]          = ST_F_QT_MAX,
 	[ST_F_AGENT_STATUS]   = 0,
 	[ST_F_AGENT_CODE]     = 0,
 	[ST_F_AGENT_DURATION] = 0,
@@ -325,6 +329,10 @@
 	[ST_F_REUSE]          = ST_F_BIN,
 	[ST_F_CACHE_LOOKUPS]  = ST_F_CACHE_HITS,
 	[ST_F_CACHE_HITS]     = ST_F_COMP_IN,
+	[ST_F_QT_MAX]         = ST_F_CT_MAX,
+	[ST_F_CT_MAX]         = ST_F_RT_MAX,
+	[ST_F_RT_MAX]         = ST_F_TT_MAX,
+	[ST_F_TT_MAX]         = ST_F_DREQ,
 };
 
 /* Matrix used to dump server metrics. Each metric points to the next one to be
@@ -391,7 +399,7 @@
 	[ST_F_QTIME]          = ST_F_CTIME,
 	[ST_F_CTIME]          = ST_F_RTIME,
 	[ST_F_RTIME]          = ST_F_TTIME,
-	[ST_F_TTIME]          = ST_F_CONNECT,
+	[ST_F_TTIME]          = ST_F_QT_MAX,
 	[ST_F_AGENT_STATUS]   = 0,
 	[ST_F_AGENT_CODE]     = 0,
 	[ST_F_AGENT_DURATION] = 0,
@@ -418,6 +426,10 @@
 	[ST_F_REUSE]          = ST_F_DRESP,
 	[ST_F_CACHE_LOOKUPS]  = 0,
 	[ST_F_CACHE_HITS]     = 0,
+	[ST_F_QT_MAX]         = ST_F_CT_MAX,
+	[ST_F_CT_MAX]         = ST_F_RT_MAX,
+	[ST_F_RT_MAX]         = ST_F_TT_MAX,
+	[ST_F_TT_MAX]         = ST_F_CONNECT,
 };
 
 /* Name of all info fields */
@@ -574,6 +586,10 @@
 	[ST_F_REUSE]          = IST("connection_reuses_total"),
 	[ST_F_CACHE_LOOKUPS]  = IST("http_cache_lookups_total"),
 	[ST_F_CACHE_HITS]     = IST("http_cache_hits_total"),
+	[ST_F_QT_MAX]         = IST("max_queue_time_seconds"),
+	[ST_F_CT_MAX]         = IST("max_connect_time_seconds"),
+	[ST_F_RT_MAX]         = IST("max_response_time_seconds"),
+	[ST_F_TT_MAX]         = IST("max_total_time_seconds"),
 };
 
 /* Description of all info fields */
@@ -730,6 +746,10 @@
 	[ST_F_REUSE]          = IST("Total number of connection reuses."),
 	[ST_F_CACHE_LOOKUPS]  = IST("Total number of HTTP cache lookups."),
 	[ST_F_CACHE_HITS]     = IST("Total number of HTTP cache hits."),
+	[ST_F_QT_MAX]         = IST("Maximum observed time spent in the queue"),
+	[ST_F_CT_MAX]         = IST("Maximum observed time spent waiting for a connection to complete"),
+	[ST_F_RT_MAX]         = IST("Maximum observed time spent waiting for a server response"),
+	[ST_F_TT_MAX]         = IST("Maximum observed total request+response time (request+queue+connect+response+processing)"),
 };
 
 /* Specific labels for all info fields. Empty by default. */
@@ -1042,6 +1062,10 @@
 	[ST_F_REUSE]          = IST("counter"),
 	[ST_F_CACHE_LOOKUPS]  = IST("counter"),
 	[ST_F_CACHE_HITS]     = IST("counter"),
+	[ST_F_QT_MAX]         = IST("gauge"),
+	[ST_F_CT_MAX]         = IST("gauge"),
+	[ST_F_RT_MAX]         = IST("gauge"),
+	[ST_F_TT_MAX]         = IST("gauge"),
 };
 
 /* Return the server status: 0=DOWN, 1=UP, 2=MAINT, 3=DRAIN, 4=NOLB. */
@@ -1674,6 +1698,22 @@
 					secs = (double)swrate_avg(px->be_counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
 					metric = mkf_flt(FN_AVG, secs);
 					break;
+				case ST_F_QT_MAX:
+					secs = (double)px->be_counters.qtime_max / 1000.0;
+					metric = mkf_flt(FN_MAX, secs);
+					break;
+				case ST_F_CT_MAX:
+					secs = (double)px->be_counters.ctime_max / 1000.0;
+					metric = mkf_flt(FN_MAX, secs);
+					break;
+				case ST_F_RT_MAX:
+					secs = (double)px->be_counters.dtime_max / 1000.0;
+					metric = mkf_flt(FN_MAX, secs);
+					break;
+				case ST_F_TT_MAX:
+					secs = (double)px->be_counters.ttime_max / 1000.0;
+					metric = mkf_flt(FN_MAX, secs);
+					break;
 				case ST_F_DREQ:
 					metric = mkf_u64(FN_COUNTER, px->be_counters.denied_req);
 					break;
@@ -1900,6 +1940,22 @@
 						secs = (double)swrate_avg(sv->counters.t_time, TIME_STATS_SAMPLES) / 1000.0;
 						metric = mkf_flt(FN_AVG, secs);
 						break;
+					case ST_F_QT_MAX:
+						secs = (double)sv->counters.qtime_max / 1000.0;
+						metric = mkf_flt(FN_MAX, secs);
+						break;
+					case ST_F_CT_MAX:
+						secs = (double)sv->counters.ctime_max / 1000.0;
+						metric = mkf_flt(FN_MAX, secs);
+						break;
+					case ST_F_RT_MAX:
+						secs = (double)sv->counters.dtime_max / 1000.0;
+						metric = mkf_flt(FN_MAX, secs);
+						break;
+					case ST_F_TT_MAX:
+						secs = (double)sv->counters.ttime_max / 1000.0;
+						metric = mkf_flt(FN_MAX, secs);
+						break;
 					case ST_F_CONNECT:
 						metric = mkf_u64(FN_COUNTER, sv->counters.connect);
 						break;