AutoKeeperCollector implements InitializingBean { public void collectorServerStat(String address) { List<String> netAddress = splitAddress(address); if (netAddress.isEmpty()) { return; } String ip = netAddress.get(0); String port = netAddress.get(1); String[] cmd = { "/bin/bash", "-c", String.format(CMD_STAT, ip, port) }; String cmdresult = collector(cmd); String[] result = cmdresult.split(WRAP); AutoKeeperServerStat summary = new AutoKeeperServerStat(); summary.setOriginalContent(cmdresult); for (String line : result) { if (line.contains(MODE_FOLLOWER)) { summary.setQuorumType(AutoKeeperQuorumType.FOLLOWER); } else if (line.contains(MODE_LEADERER)) { summary.setQuorumType(AutoKeeperQuorumType.LEADER); } else if (line.contains(MODE_STANDALONE)) { summary.setQuorumType(AutoKeeperQuorumType.STANDALONE); } else if (line.contains(MODE_OBSERVER)) { summary.setQuorumType(AutoKeeperQuorumType.OBSERVER); } else if (line.contains(STRING_LATENCY)) { List<String> latency = Arrays.asList(StringUtils.trimToEmpty(line.replace(STRING_LATENCY, StringUtils.EMPTY)).split("/")); summary.setMinLatency(Long.parseLong(latency.get(0))); summary.setAvgLatency(Long.parseLong(latency.get(1))); summary.setMaxLatency(Long.parseLong(latency.get(2))); } else if (line.contains(STRING_OUTSTANDING)) { summary.setQueued(Long.parseLong(StringUtils.trimToEmpty(line.replace(STRING_OUTSTANDING, StringUtils.EMPTY)))); } else if (line.contains(NODE_COUNT)) { summary.setNodeCount(Long.parseLong(StringUtils.trimToEmpty(line.replace(NODE_COUNT, StringUtils.EMPTY)))); } else if (line.contains(STRING_SENT)) { summary.setSent(Long.parseLong(StringUtils.trimToEmpty(line.replace(STRING_SENT, StringUtils.EMPTY)))); } else if (line.contains(STRING_RECEIVED)) { summary.setRecved(Long.parseLong(StringUtils.trimToEmpty(line.replace(STRING_RECEIVED, StringUtils.EMPTY)))); } } autoKeeperData.joinServer(address, summary); }  void collectorConnectionStat(String address); void collectorServerStat(String address); void collectorEphemeralStat(String address); void collectorWatchStat(String address); static String collector(String[] command); @Override void afterPropertiesSet(); void setAutoKeeperClusterService(AutoKeeperClusterService autoKeeperClusterService); void setAutoKeeperData(AutoKeeperData autoKeeperData); void setCollectInterval(long collectInterval);  }
@Test public void testCollectorServerStat() { autoKeeperCollector.collectorServerStat(ADDRESS); autoKeeperCollector.collectorConnectionStat(ADDRESS); autoKeeperCollector.collectorWatchStat(ADDRESS); autoKeeperCollector.collectorEphemeralStat(ADDRESS); AutoKeeperServerStat stat = autoKeeperStatService.findServerStat(ADDRESS); Set<AutoKeeperConnectionStat> conns = stat.getConnectionStats(); for (AutoKeeperConnectionStat autoKeeperConnectionStat : conns) { autoKeeperStatService.findConnectionBySessionId(autoKeeperConnectionStat.getSessionId()); autoKeeperStatService.findServerStatBySessionId(autoKeeperConnectionStat.getSessionId()); String path = autoKeeperConnectionStat.getClientAddress(); System.out.println(path); } }