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')}} - + {{$index + 1}} @@ -97,7 +97,8 @@ - + + @@ -107,6 +108,10 @@ @@ -131,6 +145,9 @@ .success { color: #33cc00; } + .warn { + color: #fabc05; + } .error { color: #ff0000; } diff --git a/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js b/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js index b9b7a4ac51..49494b4b4b 100755 --- a/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js +++ b/dolphinscheduler-ui/src/js/module/i18n/locale/en_US.js @@ -506,6 +506,7 @@ export default { 'Query time': 'Query time', 'Node self-test status': 'Node self-test status', 'Health status': 'Health status', + 'Can not connect to zookeeper server:': 'Can not connect to zookeeper server:', 'Max connections': 'Max connections', 'Threads connections': 'Threads connections', 'Max used connections': 'Max used connections', diff --git a/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js b/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js index 3039c28f21..2f48e4e02d 100755 --- a/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js +++ b/dolphinscheduler-ui/src/js/module/i18n/locale/zh_CN.js @@ -506,6 +506,7 @@ export default { 'Query time': '当前查询时间', 'Node self-test status': '节点自检状态', 'Health status': '健康状态', + 'Can not connect to zookeeper server:': 'zk节点连接失败:', 'Max connections': '最大连接数', 'Threads connections': '当前连接数', 'Max used connections': '同时使用连接最大数',