Search in sources :

Example 1 with AutoKeeperServerStat

use of com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperServerStat in project otter by alibaba.

the class AutoKeeperCollector method collectorServerStat.

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);
}
Also used : AutoKeeperServerStat(com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperServerStat)

Example 2 with AutoKeeperServerStat

use of com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperServerStat in project otter by alibaba.

the class AutoKeeperClientPath method execute.

public void execute(@Param("clusterId") String clusterId, @Param("address") String address, Context context) throws Exception {
    AutoKeeperCluster autoKeeperCluster = autoKeeperClusterService.findAutoKeeperClusterById(Long.valueOf(clusterId));
    Set<AutoKeeperConnectionStat> autoKeeperConnectionStats = new HashSet<AutoKeeperConnectionStat>();
    for (String ipAddress : autoKeeperCluster.getServerList()) {
        if (ipAddress.equalsIgnoreCase(address)) {
            AutoKeeperServerStat autoKeeperServerStat = autoKeeperStatService.findServerStat(ipAddress);
            if (autoKeeperServerStat != null) {
                autoKeeperConnectionStats = autoKeeperServerStat.getConnectionStats();
            } else {
                autoKeeperConnectionStats = new HashSet<AutoKeeperConnectionStat>();
            }
        }
    }
    context.put("autoKeeperConnectionStats", autoKeeperConnectionStats);
}
Also used : AutoKeeperConnectionStat(com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperConnectionStat) AutoKeeperCluster(com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperCluster) AutoKeeperServerStat(com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperServerStat) HashSet(java.util.HashSet)

Example 3 with AutoKeeperServerStat

use of com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperServerStat in project otter by alibaba.

the class AutoKeeperCollectorTest method testCollectorServerStat.

@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);
    }
}
Also used : AutoKeeperConnectionStat(com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperConnectionStat) AutoKeeperServerStat(com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperServerStat) BaseOtterTest(com.alibaba.otter.manager.biz.BaseOtterTest) Test(org.testng.annotations.Test)

Example 4 with AutoKeeperServerStat

use of com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperServerStat in project otter by alibaba.

the class AutoKeeperClustersDetail method execute.

public void execute(@Param("clusterId") String clusterId, Context context) throws Exception {
    Map<String, AutoKeeperServerStat> statMap = new HashMap<String, AutoKeeperServerStat>();
    AutoKeeperCluster autoKeeperCluster = autoKeeperClusterService.findAutoKeeperClusterById(Long.valueOf(clusterId));
    for (String address : autoKeeperCluster.getServerList()) {
        AutoKeeperServerStat autoKeeperServerStat = autoKeeperStatService.findServerStat(address);
        statMap.put(address, autoKeeperServerStat);
    }
    context.put("clusterId", clusterId);
    context.put("statMap", statMap);
}
Also used : HashMap(java.util.HashMap) AutoKeeperCluster(com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperCluster) AutoKeeperServerStat(com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperServerStat)

Aggregations

AutoKeeperServerStat (com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperServerStat)4 AutoKeeperCluster (com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperCluster)2 AutoKeeperConnectionStat (com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperConnectionStat)2 BaseOtterTest (com.alibaba.otter.manager.biz.BaseOtterTest)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Test (org.testng.annotations.Test)1