MINOR: contrib/prometheus-exporter: Add heathcheck status/code in server metrics

ST_F_CHECK_STATUS and ST_F_CHECK_CODE are now part of exported server metrics:

  * haproxy_server_check_status
  * haproxy_server_check_code

The heathcheck status is an integer corresponding to HCHK_STATUS value.

(cherry picked from commit cf403f32e4bd5217064f8831930b45c5fb37131b)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit f7d4218967314c5673fff2793e1a1e5681eb756b)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/contrib/prometheus-exporter/service-prometheus.c b/contrib/prometheus-exporter/service-prometheus.c
index c34ee0e1..b7c24ad 100644
--- a/contrib/prometheus-exporter/service-prometheus.c
+++ b/contrib/prometheus-exporter/service-prometheus.c
@@ -367,7 +367,7 @@
 	[ST_F_WRETR]          = ST_F_WREDIS,
 	[ST_F_WREDIS]         = ST_F_WREW,
 	[ST_F_STATUS]         = ST_F_SCUR,
-	[ST_F_WEIGHT]         = ST_F_CHKFAIL,
+	[ST_F_WEIGHT]         = ST_F_CHECK_STATUS,
 	[ST_F_ACT]            = 0,
 	[ST_F_BCK]            = 0,
 	[ST_F_CHKFAIL]        = ST_F_CHKDOWN,
@@ -385,8 +385,8 @@
 	[ST_F_RATE]           = 0,
 	[ST_F_RATE_LIM]       = 0,
 	[ST_F_RATE_MAX]       = ST_F_LASTSESS,
-	[ST_F_CHECK_STATUS]   = 0,
-	[ST_F_CHECK_CODE]     = 0,
+	[ST_F_CHECK_STATUS]   = ST_F_CHECK_CODE,
+	[ST_F_CHECK_CODE]     = ST_F_CHKFAIL,
 	[ST_F_CHECK_DURATION] = 0,
 	[ST_F_HRSP_1XX]       = ST_F_HRSP_2XX,
 	[ST_F_HRSP_2XX]       = ST_F_HRSP_3XX,
@@ -709,7 +709,7 @@
 	[ST_F_RATE]           = IST("Current number of sessions per second over last elapsed second."),
 	[ST_F_RATE_LIM]       = IST("Configured limit on new sessions per second."),
 	[ST_F_RATE_MAX]       = IST("Maximum observed number of sessions per second."),
-	[ST_F_CHECK_STATUS]   = IST("Status of last health check (If a check is running, the status will be reported, prefixed with '* ')."),
+	[ST_F_CHECK_STATUS]   = IST("Status of last health check (HCHK_STATUS_* values)."),
 	[ST_F_CHECK_CODE]     = IST("layer5-7 code, if available of the last health check."),
 	[ST_F_CHECK_DURATION] = IST("Time in ms took to finish last health check."),
 	[ST_F_HRSP_1XX]       = IST("Total number of HTTP responses."),
@@ -1027,8 +1027,8 @@
 	[ST_F_RATE]           = IST("untyped"),
 	[ST_F_RATE_LIM]       = IST("gauge"),
 	[ST_F_RATE_MAX]       = IST("gauge"),
-	[ST_F_CHECK_STATUS]   = IST("untyped"),
-	[ST_F_CHECK_CODE]     = IST("untyped"),
+	[ST_F_CHECK_STATUS]   = IST("gauge"),
+	[ST_F_CHECK_CODE]     = IST("gauge"),
 	[ST_F_CHECK_DURATION] = IST("gauge"),
 	[ST_F_HRSP_1XX]       = IST("counter"),
 	[ST_F_HRSP_2XX]       = IST("counter"),
@@ -2012,6 +2012,16 @@
 						weight = (sv->cur_eweight * px->lbprm.wmult + px->lbprm.wdiv - 1) / px->lbprm.wdiv;
 						metric = mkf_u32(FN_AVG, weight);
 						break;
+					case ST_F_CHECK_STATUS:
+						if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
+							goto next_sv;
+						metric = mkf_u32(FN_OUTPUT, sv->check.status);
+						break;
+					case ST_F_CHECK_CODE:
+						if ((sv->check.state & (CHK_ST_ENABLED|CHK_ST_PAUSED)) != CHK_ST_ENABLED)
+							goto next_sv;
+						metric = mkf_u32(FN_OUTPUT, (sv->check.status < HCHK_STATUS_L57DATA) ? 0 : sv->check.code);
+						break;
 					case ST_F_CHKFAIL:
 						metric = mkf_u64(FN_COUNTER, sv->counters.failed_checks);
 						break;