]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stats: report the number of active peers in "show info"
authorWilly Tarreau <w@1wt.eu>
Mon, 5 Nov 2018 15:31:22 +0000 (16:31 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 5 Nov 2018 16:15:21 +0000 (17:15 +0100)
Peers are the last type of activity which can maintain a job present, so
it's important to report that such an entity is still active to explain
why the job count may be higher than zero. Here by "ActivePeers" we report
peers sessions, which include both established connections and outgoing
connection attempts.

include/types/global.h
include/types/stats.h
src/haproxy.c
src/peers.c
src/stats.c

index 4b9d019ed57523639cd52f45fc8fea0cd8f80a2a..18cc63e6c514bcf10a7fc5ee48209a6573aa9f67 100644 (file)
@@ -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;
index 8df848978ddc9cd1bdde222b66521e54e444f0c2..e59a240dd944efddf6157b8a3552b275688fcd8d 100644 (file)
@@ -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
index 81db3e0fdea3f897054a1756c2a6eaed01ce6b1d..129ff1d5ed8b636f91f8d5bf0b0ef2561f9d117f 100644 (file)
@@ -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
index a99d8e166da11ea55341c2fd397ad098c205b618..1d6dac1226ca808a8d0473ef953970b34ec6b18e 100644 (file)
@@ -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 */
index cbb9870024149ed7ace2d1c137718cc087d555b9..231c17292dff273f0e036d67f7ab8b261c186d03 100644 (file)
@@ -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;
 }