message: Metrics for idle connections in ClientPool
diff: @@ -246,7 +246,43 @@ ClientPool.prototype.totalReconnectsWaiting = function (serverDomain) {
  return this._reconnectQueues[serverDomain].waitingItems;
  }
  return 0;
  +};
  +
  +ClientPool.prototype.getIdleConnectionMetrics = function() {
  + return new Promise((resolve) => {
  + resolve(this._calculateIdleConnectionMetrics());
  + });
  +};
  +
  +ClientPool.prototype._calculateIdleConnectionMetrics = function(server) {
  + const SEVEN_DAYS_MS = 1000 * 60 * 60 * 24 * 7;
  + const periodBucketTimes = {
  + "7d": Date.now() - SEVEN_DAYS_MS,
  + "14d": Date.now() - SEVEN_DAYS_MS*2,
  + "21d": Date.now() - SEVEN_DAYS_MS*3,
  + };
  +
  + const _idleConnectionMetrics = {
  + "7d": 0,
  + "14d": 0,
  + "21d": 0,
  + };
  + const clients = Object.values(this._virtualClients[server].userIds);
  + for (const bridgedClient of clients) {
  + const lastActionMS = bridgedClient.getLastActionTs();
  + let bucket = null;
  + for (const periodBucket in periodBucketTimes) {
  + if (lastActionMS > periodBucketTimes[periodBucket]) {
  + break;
  + }
  + bucket = periodBucket;
  }
  + if (bucket !== null) {
  + _idleConnectionMetrics[bucket]++;
  + }
  + }
  + return _idleConnectionMetrics;
  +};
  ClientPool.prototype._sendConnectionMetric = function(server) {
  stats.ircClients(server.domain, this._getNumberOfConnections(server));
  