From 3fc0fe05fd8e111a832c18fb27afbf0f85fcf03e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20L=C3=A9caille?= Date: Thu, 8 Oct 2020 09:46:24 +0200 Subject: [PATCH] MINOR: peers: heartbeat, collisions and handshake information for "show peers" command. This patch adds "coll" new counter and the heartbeat timer values to "show peers" command. It also adds the elapsed time since the last handshake to new "last_hdshk" new peer dump field. --- include/haproxy/peers-t.h | 2 ++ src/peers.c | 26 ++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/haproxy/peers-t.h b/include/haproxy/peers-t.h index 41e94d45b..5d035c3be 100644 --- a/include/haproxy/peers-t.h +++ b/include/haproxy/peers-t.h @@ -65,11 +65,13 @@ struct peer { unsigned int reconnect; /* next connect timer */ unsigned int heartbeat; /* next heartbeat timer */ unsigned int confirm; /* confirm message counter */ + unsigned int last_hdshk; /* Date of the last handshake. */ uint32_t rx_hbt; /* received heartbeats counter */ uint32_t tx_hbt; /* transmitted heartbeats counter */ uint32_t no_hbt; /* no received heartbeat counter */ uint32_t new_conn; /* new connection after reconnection timeout expiration counter */ uint32_t proto_err; /* protocol errors counter */ + uint32_t coll; /* connection collisions counter */ struct appctx *appctx; /* the appctx running it */ struct shared_table *remote_table; struct shared_table *last_local_table; diff --git a/src/peers.c b/src/peers.c index 3edd643d6..1b05dbd84 100644 --- a/src/peers.c +++ b/src/peers.c @@ -2122,6 +2122,7 @@ static inline void init_accepted_peer(struct peer *peer, struct peers *peers) /* Register status code */ peer->statuscode = PEER_SESS_SC_SUCCESSCODE; + peer->last_hdshk = now_ms; /* Awake main task */ task_wakeup(peers->sync_task, TASK_WOKEN_MSG); @@ -2270,6 +2271,7 @@ switchstate: */ curpeer->reconnect = tick_add(now_ms, MS_TO_TICKS(50 + ha_random() % 2000)); peer_session_forceshutdown(curpeer); + curpeer->coll++; } if (maj_ver != (unsigned int)-1 && min_ver != (unsigned int)-1) { if (min_ver == PEER_DWNGRD_MINOR_VER) { @@ -2355,6 +2357,7 @@ switchstate: /* Register status code */ curpeer->statuscode = atoi(trash.area); + curpeer->last_hdshk = now_ms; /* Awake main task */ task_wakeup(curpeers->sync_task, TASK_WOKEN_MSG); @@ -2544,6 +2547,7 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer peer->reconnect = tick_add(now_ms, MS_TO_TICKS(PEER_RECONNECT_TIMEOUT)); peer->heartbeat = tick_add(now_ms, MS_TO_TICKS(PEER_HEARTBEAT_TIMEOUT)); peer->statuscode = PEER_SESS_SC_CONNECTCODE; + peer->last_hdshk = now_ms; s = NULL; appctx = appctx_new(&peer_applet, tid_bit); @@ -3100,18 +3104,32 @@ static int peers_dump_peer(struct buffer *msg, struct stream_interface *si, stru struct shared_table *st; addr_to_str(&peer->addr, pn, sizeof pn); - chunk_appendf(msg, " %p: id=%s(%s,%s) addr=%s:%d last_status=%s reconnect=%s confirm=%u tx_hbt=%u rx_hbt=%u no_hbt=%u new_conn=%u proto_err=%u\n", + chunk_appendf(msg, " %p: id=%s(%s,%s) addr=%s:%d last_status=%s", peer, peer->id, peer->local ? "local" : "remote", peer->appctx ? "active" : "inactive", pn, get_host_port(&peer->addr), - statuscode_str(peer->statuscode), + statuscode_str(peer->statuscode)); + + chunk_appendf(msg, " last_hdshk=%s\n", + peer->last_hdshk ? human_time(TICKS_TO_MS(now_ms - peer->last_hdshk), + TICKS_TO_MS(1000)) : ""); + + chunk_appendf(msg, " reconnect=%s", peer->reconnect ? tick_is_expired(peer->reconnect, now_ms) ? "" : human_time(TICKS_TO_MS(peer->reconnect - now_ms), - TICKS_TO_MS(1000)) : "", + TICKS_TO_MS(1000)) : ""); + + chunk_appendf(msg, " heartbeat=%s", + peer->heartbeat ? + tick_is_expired(peer->heartbeat, now_ms) ? "" : + human_time(TICKS_TO_MS(peer->heartbeat - now_ms), + TICKS_TO_MS(1000)) : ""); + + chunk_appendf(msg, " confirm=%u tx_hbt=%u rx_hbt=%u no_hbt=%u new_conn=%u proto_err=%u coll=%u\n", peer->confirm, peer->tx_hbt, peer->rx_hbt, - peer->no_hbt, peer->new_conn, peer->proto_err); + peer->no_hbt, peer->new_conn, peer->proto_err, peer->coll); chunk_appendf(&trash, " flags=0x%x", peer->flags);