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);
}
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);
}
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);
}
}
Aggregations