diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/FourLetterWordMain.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/FourLetterWordMain.java index 340a389d1c..6136c2021e 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/FourLetterWordMain.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/FourLetterWordMain.java @@ -25,10 +25,12 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; + import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.net.SocketTimeoutException; +import java.net.ConnectException; import java.util.Objects; public class FourLetterWordMain { @@ -88,7 +90,7 @@ public class FourLetterWordMain { } return sb.toString(); } - } catch (SocketTimeoutException e) { + } catch (SocketTimeoutException | ConnectException e ) { throw new IOException("Exception while executing four letter word: " + cmd, e); } } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/ZooKeeperState.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/ZooKeeperState.java index 55bb3d336c..ff85c40046 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/ZooKeeperState.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/ZooKeeperState.java @@ -16,6 +16,7 @@ */ package org.apache.dolphinscheduler.api.utils; +import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.utils.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,6 +44,8 @@ public class ZooKeeperState { private int watches = -1; private int connections = -1; + private boolean healthFlag = false; + public ZooKeeperState(String connectionString) { String host = connectionString.substring(0, connectionString.indexOf(':')); @@ -55,55 +58,68 @@ public class ZooKeeperState { public void getZookeeperInfo() { String content = cmd("srvr"); if (StringUtils.isNotBlank(content)) { - try (Scanner scannerForStat = new Scanner(content)) { - while (scannerForStat.hasNext()) { - String line = scannerForStat.nextLine(); - if (line.startsWith("Latency min/avg/max:")) { - String[] latencys = getStringValueFromLine(line).split("/"); - minLatency = Float.parseFloat(latencys[0]); - avgLatency = Float.parseFloat(latencys[1]); - maxLatency = Float.parseFloat(latencys[2]); - } else if (line.startsWith("Received:")) { - received = Long.parseLong(getStringValueFromLine(line)); - } else if (line.startsWith("Sent:")) { - sent = Long.parseLong(getStringValueFromLine(line)); - } else if (line.startsWith("Outstanding:")) { - outStanding = Integer.parseInt(getStringValueFromLine(line)); - } else if (line.startsWith("Zxid:")) { - zxid = Long.parseLong(getStringValueFromLine(line).substring(2), 16); - } else if (line.startsWith("Mode:")) { - mode = getStringValueFromLine(line); - } else if (line.startsWith("Node count:")) { - nodeCount = Integer.parseInt(getStringValueFromLine(line)); + if(Constants.STRING_FALSE.equals(content)){ + healthFlag = true; + }else { + try (Scanner scannerForStat = new Scanner(content)) { + while (scannerForStat.hasNext()) { + String line = scannerForStat.nextLine(); + if (line.startsWith("Latency min/avg/max:")) { + String[] latencys = getStringValueFromLine(line).split("/"); + minLatency = Float.parseFloat(latencys[0]); + avgLatency = Float.parseFloat(latencys[1]); + maxLatency = Float.parseFloat(latencys[2]); + } else if (line.startsWith("Received:")) { + received = Long.parseLong(getStringValueFromLine(line)); + } else if (line.startsWith("Sent:")) { + sent = Long.parseLong(getStringValueFromLine(line)); + } else if (line.startsWith("Outstanding:")) { + outStanding = Integer.parseInt(getStringValueFromLine(line)); + } else if (line.startsWith("Zxid:")) { + zxid = Long.parseLong(getStringValueFromLine(line).substring(2), 16); + } else if (line.startsWith("Mode:")) { + mode = getStringValueFromLine(line); + } else if (line.startsWith("Node count:")) { + nodeCount = Integer.parseInt(getStringValueFromLine(line)); + } } } - } + } + } String wchsText = cmd("wchs"); if (StringUtils.isNotBlank(wchsText)) { - try (Scanner scannerForWchs = new Scanner(wchsText)) { - while (scannerForWchs.hasNext()) { - String line = scannerForWchs.nextLine(); - if (line.startsWith("Total watches:")) { - watches = Integer.parseInt(getStringValueFromLine(line)); + if(Constants.STRING_FALSE.equals(wchsText)){ + healthFlag = true; + }else { + try (Scanner scannerForWchs = new Scanner(wchsText)) { + while (scannerForWchs.hasNext()) { + String line = scannerForWchs.nextLine(); + if (line.startsWith("Total watches:")) { + watches = Integer.parseInt(getStringValueFromLine(line)); + } } } - } + } } String consText = cmd("cons"); if (StringUtils.isNotBlank(consText)) { - Scanner scannerForCons = new Scanner(consText); - if (StringUtils.isNotBlank(consText)) { - connections = 0; - } - while (scannerForCons.hasNext()) { - @SuppressWarnings("unused") - String line = scannerForCons.nextLine(); - ++connections; + if(Constants.STRING_FALSE.equals(consText)){ + healthFlag = true; + }else { + Scanner scannerForCons = new Scanner(consText); + if (StringUtils.isNotBlank(consText)) { + connections = 0; + } + while (scannerForCons.hasNext()) { + @SuppressWarnings("unused") + String line = scannerForCons.nextLine(); + ++connections; + } + scannerForCons.close(); } - scannerForCons.close(); } } @@ -121,7 +137,7 @@ public class ZooKeeperState { private class SendThread extends Thread { private String cmd; - private String ret = ""; + private String ret = Constants.STRING_FALSE; public SendThread(String cmd) { this.cmd = cmd; @@ -150,7 +166,7 @@ public class ZooKeeperState { } catch (InterruptedException e) { logger.error("send " + cmd + " to server " + host + ":" + port + " failed!", e); } - return ""; + return Constants.STRING_FALSE; } public Logger getLogger() { @@ -209,6 +225,10 @@ public class ZooKeeperState { return connections; } + public boolean isHealthFlag() { + return healthFlag; + } + @Override public String toString() { return "ZooKeeperState [host=" + host + ", port=" + port @@ -217,7 +237,7 @@ public class ZooKeeperState { + ", sent=" + sent + ", outStanding=" + outStanding + ", zxid=" + zxid + ", mode=" + mode + ", nodeCount=" + nodeCount + ", watches=" + watches + ", connections=" - + connections + "]"; + + connections + ",healthFlag=" + healthFlag + "]"; } diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/ZookeeperMonitor.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/ZookeeperMonitor.java index 9fd4386d20..bd0e73fdfd 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/ZookeeperMonitor.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/ZookeeperMonitor.java @@ -78,9 +78,7 @@ public class ZookeeperMonitor extends AbstractZKClient { for (String zookeeperServer : zookeeperServersArray) { ZooKeeperState state = new ZooKeeperState(zookeeperServer); boolean ok = state.ruok(); - if (ok) { - state.getZookeeperInfo(); - } + state.getZookeeperInfo(); int connections = state.getConnections(); int watches = state.getWatches(); @@ -91,7 +89,7 @@ public class ZookeeperMonitor extends AbstractZKClient { float avgLatency = state.getAvgLatency(); float maxLatency = state.getMaxLatency(); int nodeCount = state.getNodeCount(); - int status = ok ? 1 : 0; + int status = state.isHealthFlag() ? -1: (ok ? 1 : 0); Date date = new Date(); ZookeeperRecord zookeeperRecord = new ZookeeperRecord(zookeeperServer,connections,watches,sent,received,mode,minLatency,avgLatency,maxLatency,nodeCount,status,date); diff --git a/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/_source/zookeeperList.vue b/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/_source/zookeeperList.vue index de187dddc8..8d8edd88f6 100644 --- a/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/_source/zookeeperList.vue +++ b/dolphinscheduler-ui/src/js/conf/home/pages/monitor/pages/servers/_source/zookeeperList.vue @@ -59,7 +59,7 @@ {{$t('Node self-test status')}} -