diff --git a/include/types/global.h b/include/types/global.h index 4b9d019ed..18cc63e6c 100644 --- a/include/types/global.h +++ b/include/types/global.h @@ -224,6 +224,7 @@ extern unsigned long pid_bit; /* bit corresponding to the process id */ extern int actconn; /* # of active sessions */ extern int listeners; extern int jobs; /* # of active jobs (listeners, sessions, open devices) */ +extern int active_peers; /* # of active peers (connection attempts and successes) */ extern THREAD_LOCAL struct buffer trash; extern int nb_oldpids; /* contains the number of old pids found */ extern const int zero; diff --git a/include/types/stats.h b/include/types/stats.h index 8df848978..e59a240dd 100644 --- a/include/types/stats.h +++ b/include/types/stats.h @@ -291,6 +291,7 @@ enum info_field { INF_STOPPING, INF_JOBS, INF_LISTENERS, + INF_ACTIVE_PEERS, /* must always be the last one */ INF_TOTAL_FIELDS diff --git a/src/haproxy.c b/src/haproxy.c index 81db3e0fd..129ff1d5e 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -175,6 +175,7 @@ struct activity activity[MAX_THREADS] __attribute__((aligned(64))) = { }; int stopping; /* non zero means stopping in progress */ int killed; /* non zero means a hard-stop is triggered */ int jobs = 0; /* number of active jobs (conns, listeners, active tasks, ...) */ +int active_peers = 0; /* number of active peers (connection attempts and connected) */ /* Here we store informations about the pids of the processes we may pause * or kill. We will send them a signal every 10 ms until we can bind to all diff --git a/src/peers.c b/src/peers.c index a99d8e166..1d6dac122 100644 --- a/src/peers.c +++ b/src/peers.c @@ -506,6 +506,7 @@ static void peer_session_release(struct appctx *appctx) /* peer session identified */ if (peer) { + HA_ATOMIC_SUB(&active_peers, 1); HA_SPIN_LOCK(PEER_LOCK, &peer->lock); if (peer->appctx == appctx) { /* Re-init current table pointers to force announcement on re-connect */ @@ -718,6 +719,7 @@ switchstate: curpeer->appctx = appctx; appctx->ctx.peers.ptr = curpeer; appctx->st0 = PEER_SESS_ST_SENDSUCCESS; + HA_ATOMIC_ADD(&active_peers, 1); /* fall through */ } case PEER_SESS_ST_SENDSUCCESS: { @@ -1979,6 +1981,7 @@ static struct appctx *peer_session_create(struct peers *peers, struct peer *peer peer->appctx = appctx; task_wakeup(s->task, TASK_WOKEN_INIT); + HA_ATOMIC_ADD(&active_peers, 1); return appctx; /* Error unrolling */ diff --git a/src/stats.c b/src/stats.c index cbb987002..231c17292 100644 --- a/src/stats.c +++ b/src/stats.c @@ -133,6 +133,7 @@ const char *info_field_names[INF_TOTAL_FIELDS] = { [INF_STOPPING] = "Stopping", [INF_JOBS] = "Jobs", [INF_LISTENERS] = "Listeners", + [INF_ACTIVE_PEERS] = "ActivePeers", }; const char *stat_field_names[ST_F_TOTAL_FIELDS] = { @@ -3298,6 +3299,7 @@ int stats_fill_info(struct field *info, int len) info[INF_STOPPING] = mkf_u32(0, stopping); info[INF_JOBS] = mkf_u32(0, jobs); info[INF_LISTENERS] = mkf_u32(0, listeners); + info[INF_ACTIVE_PEERS] = mkf_u32(0, active_peers); return 1; }