This is an automated email from the ASF dual-hosted git repository.

kirs pushed a commit to branch 1.3.7-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/1.3.7-prepare by this push:
     new 58b2672  [#5748][refactor]get more reasonable monitoring indexes of 
the zk cluster (#5768)
58b2672 is described below

commit 58b2672be9d22bf98a5310834f7d839c93c4029e
Author: jon-qj <[email protected]>
AuthorDate: Thu Jul 8 18:19:11 2021 +0800

    [#5748][refactor]get more reasonable monitoring indexes of the zk cluster 
(#5768)
    
    * [#5748][refactor]get more reasonable monitoring indexes of the cluster
    
    add warning state on the front-end
    each zk node shows monitoring indexes correctly
    
    Co-authored-by: unknown <[email protected]>
---
 .../api/utils/FourLetterWordMain.java              |  4 +-
 .../dolphinscheduler/api/utils/ZooKeeperState.java | 98 +++++++++++++---------
 .../api/utils/ZookeeperMonitor.java                |  6 +-
 .../pages/servers/_source/zookeeperList.vue        | 21 ++++-
 .../src/js/module/i18n/locale/en_US.js             |  1 +
 .../src/js/module/i18n/locale/zh_CN.js             |  1 +
 6 files changed, 85 insertions(+), 46 deletions(-)

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 340a389..6136c20 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 55bb3d3..ff85c40 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 9fd4386..bd0e73f 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 de187dd..8d8edd8 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 @@
             <span>{{$t('Node self-test status')}}</span>
           </th>
         </tr>
-        <tr v-for="(item, $index) in list" :key="$index">
+        <tr v-for="(item, $index) in list" :key="$index" 
@mouseenter="_showErrorMessage(item)">
           <td>
             <span>{{$index + 1}}</span>
           </td>
@@ -97,7 +97,8 @@
           </td>
           <td>
             <span class="state">
-              <em class="ans-icon-success-solid success" 
v-if="item.state"></em>
+              <em class="ans-icon-success-solid success" v-if="item.state === 
1"></em>
+              <em class="ans-icon-warn-solid warn" v-else-if="item.state === 
0"></em>
               <em class="ans-icon-fail-solid error" v-else></em>
             </span>
           </td>
@@ -107,6 +108,10 @@
   </div>
 </template>
 <script>
+
+  import _ from 'lodash'
+  import i18n from '@/module/i18n'
+
   export default {
     name: 'zookeeper-list',
     data () {
@@ -116,6 +121,15 @@
     },
     props: {
       list: Array
+    },
+    methods:{
+      _showErrorMessage:_.debounce(function (item){
+        const hostname = item.hostname
+        const state = item.state
+        if(state === -1){
+          this.$message.error(`${i18n.$t('Can not connect to zookeeper 
server:')}`+hostname)
+        }
+      },600)
     }
   }
 </script>
@@ -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 b9b7a4a..49494b4 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 3039c28..2f48e4e 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': '同时使用连接最大数',

Reply via email to