message: Refactor so that all homeserver states are recorded
diff: @@ -517,23 +517,31 @@ export class ClientPool {
  allClients: Gauge<string>, clientsByHomeserver: Gauge<string>, clientsByHomeserverMax: number
  ) {
  allClients.reset();
  - const homeserverStats: {[stateHomeserver: string]: number} = { };
  + const homeserverStats: {[homeserver: string]: {[state: string]: number}} = { };
  for (const [domain, {userIds}] of Object.entries(this.virtualClients)) {
  for (const client of userIds.values()) {
  const state = BridgedClientStatus[client.status].toLowerCase();
  allClients.inc({ server: domain, state });
  if (client.matrixUser) {
  - const key = state + ":" + client.matrixUser.host;
  - homeserverStats[key] = (homeserverStats[key] || 0) + 1;
  + const key = client.matrixUser.host;
  + if (!homeserverStats[key]) {
  + homeserverStats[key] = {
  + connected: 0,
  + }
  + }
  + homeserverStats[key][state] = (homeserverStats[key][state] || 0) + 1;
  }
  }
  }
  clientsByHomeserver.reset();
  // We intentionally limit the number of clients to reduce label bloat.
  - Object.entries(homeserverStats).sort(((a, b) => b[1] - a[1])).slice(0, clientsByHomeserverMax - 1).forEach(
  - ([homeserverState, count]) => {
  - const [state, homeserver] = homeserverState.split(':');
  + Object.entries(homeserverStats)
  + .sort(((a, b) => b[1]["connected"] - a[1]["connnected"]))
  + .slice(0, clientsByHomeserverMax-1).forEach(
  + ([homeserver, stateSet]) => {
  + Object.entries(stateSet).forEach(([state, count]) => {
  clientsByHomeserver.set({ homeserver, state }, count);
  + });
  }
  );
  }
  