Search in sources :

Example 1 with AutoKeeperConnectionStat

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

the class AutoKeeperCollector method collectorConnectionStat.

public void collectorConnectionStat(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_CONS, ip, port) };
    String cmdresult = collector(cmd);
    String[] result = cmdresult.split(WRAP);
    List<AutoKeeperConnectionStat> summary = new ArrayList<AutoKeeperConnectionStat>();
    for (String line : result) {
        if (StringUtils.isBlank(line)) {
            continue;
        }
        String[] lineArray = line.split(":");
        if (2 != lineArray.length) {
            continue;
        }
        AutoKeeperConnectionStat autoKeeperConnectionStat = new AutoKeeperConnectionStat();
        autoKeeperConnectionStat.setOriginalContent(line);
        String clientIp = StringUtils.trimToEmpty(line.split(":")[0].replace("/", ""));
        String sessionId = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "sid=(?s).*?[,)]")).replace("sid=", StringUtils.EMPTY).replace(COMMA, StringUtils.EMPTY).replace(BRACKETS, StringUtils.EMPTY);
        String queued = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "queued=(?s).*?[,)]")).replace("queued=", StringUtils.EMPTY).replace(COMMA, StringUtils.EMPTY).replace(BRACKETS, StringUtils.EMPTY);
        String receive = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "recved=(?s).*?[,)]")).replace("recved=", StringUtils.EMPTY).replace(COMMA, StringUtils.EMPTY).replace(BRACKETS, StringUtils.EMPTY);
        String sent = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "sent=(?s).*?[,)]")).replace("sent=", StringUtils.EMPTY).replace(COMMA, StringUtils.EMPTY).replace(BRACKETS, StringUtils.EMPTY);
        String minlat = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "minlat=(?s).*?[,)]")).replace("minlat=", StringUtils.EMPTY).replace(COMMA, StringUtils.EMPTY).replace(BRACKETS, StringUtils.EMPTY);
        String avglat = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "avglat=(?s).*?[,)]")).replace("avglat=", StringUtils.EMPTY).replace(COMMA, StringUtils.EMPTY).replace(BRACKETS, StringUtils.EMPTY);
        String maxlat = StringUtils.trimToEmpty(RegexUtils.findFirst(line.split(":")[1], "maxlat=(?s).*?[,)]")).replace("maxlat=", StringUtils.EMPTY).replace(COMMA, StringUtils.EMPTY).replace(BRACKETS, StringUtils.EMPTY);
        autoKeeperConnectionStat.setServerAddress(ip);
        autoKeeperConnectionStat.setClientAddress(clientIp);
        autoKeeperConnectionStat.setSessionId(sessionId);
        if (StringUtils.isNotEmpty(queued)) {
            autoKeeperConnectionStat.setQueued(Long.parseLong(queued));
        }
        if (StringUtils.isNotEmpty(receive)) {
            autoKeeperConnectionStat.setRecved(Long.parseLong(receive));
        }
        if (StringUtils.isNotEmpty(sent)) {
            autoKeeperConnectionStat.setSent(Long.parseLong(sent));
        }
        if (StringUtils.isNotEmpty(minlat)) {
            autoKeeperConnectionStat.setMinLatency(Long.parseLong(minlat));
        }
        if (StringUtils.isNotEmpty(avglat)) {
            autoKeeperConnectionStat.setAvgLatency(Long.parseLong(avglat));
        }
        if (StringUtils.isNotEmpty(maxlat)) {
            autoKeeperConnectionStat.setMaxLatency(Long.parseLong(maxlat));
        }
        summary.add(autoKeeperConnectionStat);
    }
    autoKeeperData.joinConnection(address, summary);
}
Also used : ArrayList(java.util.ArrayList) AutoKeeperConnectionStat(com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperConnectionStat)

Example 2 with AutoKeeperConnectionStat

use of com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperConnectionStat 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 AutoKeeperConnectionStat

use of com.alibaba.otter.shared.common.model.autokeeper.AutoKeeperConnectionStat 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)

Aggregations

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