You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ge...@apache.org on 2020/02/06 15:37:19 UTC

[incubator-iotdb] 01/05: refactor metrics and create http api

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

geniuspig pushed a commit to branch http
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git

commit 7f00b75551c66d5d6bc76258d663e05dc8cf19d1
Author: zhutianci <zh...@gmail.com>
AuthorDate: Mon Feb 3 11:14:19 2020 +0800

    refactor metrics and create http api
---
 .../org/apache/iotdb/db/http/QueryServlet.java     | 44 ++++++++++
 .../java/org/apache/iotdb/db/http/TimeValues.java  | 47 +++++++++++
 .../apache/iotdb/db/http/service/HttpService.java  |  5 ++
 .../apache/iotdb/db/metrics/server/JettyUtil.java  | 20 ++---
 .../iotdb/db/metrics/server/MetricsSystem.java     | 22 ++---
 .../iotdb/db/metrics/server/QueryServlet.java      |  6 +-
 .../iotdb/db/metrics/server/ServerArgument.java    | 51 +++++-------
 .../iotdb/db/metrics/server/SqlArgument.java       |  6 +-
 .../apache/iotdb/db/metrics/sink/ConsoleSink.java  |  6 +-
 .../iotdb/db/metrics/sink/MetricsServletSink.java  |  4 +-
 .../org/apache/iotdb/db/metrics/sink/Sink.java     |  8 +-
 .../apache/iotdb/db/metrics/source/JvmSource.java  |  6 +-
 .../iotdb/db/metrics/source/MetricsSource.java     | 96 ++++++++--------------
 .../org/apache/iotdb/db/metrics/source/Source.java |  4 +-
 .../apache/iotdb/db/metrics/ui/MetricsPage.java    | 86 +++++++++----------
 .../apache/iotdb/db/metrics/ui/MetricsWebUI.java   | 16 +---
 .../apache/iotdb/db/service/MetricsService.java    |  2 +-
 17 files changed, 229 insertions(+), 200 deletions(-)

diff --git a/server/src/main/java/org/apache/iotdb/db/http/QueryServlet.java b/server/src/main/java/org/apache/iotdb/db/http/QueryServlet.java
new file mode 100644
index 0000000..d042663
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/http/QueryServlet.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.http;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+public class QueryServlet extends HttpServlet {
+
+  @Override
+  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+      throws ServletException, IOException {
+    PrintWriter out = resp.getWriter();
+    resp.setContentType("application/json");
+    resp.setCharacterEncoding("UTF-8");
+
+  }
+
+  @Override
+  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+      throws ServletException, IOException {
+    super.doPost(req, resp);
+  }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/http/TimeValues.java b/server/src/main/java/org/apache/iotdb/db/http/TimeValues.java
new file mode 100644
index 0000000..8c7059d
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/http/TimeValues.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.http;
+
+public class TimeValues {
+
+  private long time;
+  private String value;
+
+  @Override
+  public String toString() {
+    return "TimeValues{" + "time=" + time + ", values=" + value + '}';
+  }
+
+  public long getTime() {
+    return time;
+  }
+
+  public void setTime(long time) {
+    this.time = time;
+  }
+
+  public String getValue() {
+    return value;
+  }
+
+  public void setValue(String value) {
+    this.value = value;
+  }
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/http/service/HttpService.java b/server/src/main/java/org/apache/iotdb/db/http/service/HttpService.java
new file mode 100644
index 0000000..87ba8ee
--- /dev/null
+++ b/server/src/main/java/org/apache/iotdb/db/http/service/HttpService.java
@@ -0,0 +1,5 @@
+package org.apache.iotdb.db.http.service;
+
+public class HttpService {
+
+}
diff --git a/server/src/main/java/org/apache/iotdb/db/metrics/server/JettyUtil.java b/server/src/main/java/org/apache/iotdb/db/metrics/server/JettyUtil.java
index f4d82f9..ab2cff1 100644
--- a/server/src/main/java/org/apache/iotdb/db/metrics/server/JettyUtil.java
+++ b/server/src/main/java/org/apache/iotdb/db/metrics/server/JettyUtil.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
  * agreements. See the NOTICE file distributed with this work for additional information regarding
  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
@@ -14,11 +14,13 @@
  */
 package org.apache.iotdb.db.metrics.server;
 
+import com.codahale.metrics.MetricRegistry;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.net.URL;
 import java.util.List;
-import javax.servlet.ServletException;
+import java.util.Objects;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -28,8 +30,6 @@ import org.eclipse.jetty.server.handler.ErrorHandler;
 import org.eclipse.jetty.servlet.DefaultServlet;
 import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
-import com.codahale.metrics.MetricRegistry;
-import com.fasterxml.jackson.databind.ObjectMapper;
 
 public class JettyUtil {
 
@@ -41,7 +41,7 @@ public class JettyUtil {
       MetricRegistry mr = metricRegistry;
 
       @Override
-      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+      protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
         resp.setContentType("text/html;charset=utf-8");
         resp.setStatus(HttpServletResponse.SC_OK);
         PrintWriter out = resp.getWriter();
@@ -52,19 +52,19 @@ public class JettyUtil {
 
       @Override
       public void doPost(HttpServletRequest req, HttpServletResponse resp)
-          throws ServletException, IOException {
+          throws IOException {
         doGet(req, resp);
       }
     };
     
-    return createServletHandler("/json", httpServlet);
+    return createServletHandler("/json", httpServlet, "/");
   }
 
-  public static ServletContextHandler createServletHandler(String path, HttpServlet servlet) {
+  public static ServletContextHandler createServletHandler(String path, HttpServlet servlet, String pathSpec) {
     ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
     ServletHolder holder = new ServletHolder(servlet);
     contextHandler.setContextPath(path);
-    contextHandler.addServlet(holder, "/");
+    contextHandler.addServlet(holder, pathSpec);
     return contextHandler;
   }
 
@@ -73,7 +73,7 @@ public class JettyUtil {
     URL res = JettyUtil.class.getClassLoader().getResource("iotdb/ui/static");
     HttpServlet servlet = new DefaultServlet();
     ServletHolder holder = new ServletHolder(servlet);
-    holder.setInitParameter("resourceBase", res.toString());
+    holder.setInitParameter("resourceBase", Objects.requireNonNull(res).toString());
     contextHandler.setContextPath("/static");
     contextHandler.addServlet(holder, "/");
     return contextHandler;
diff --git a/server/src/main/java/org/apache/iotdb/db/metrics/server/MetricsSystem.java b/server/src/main/java/org/apache/iotdb/db/metrics/server/MetricsSystem.java
index 7e6e04d..7872b14 100644
--- a/server/src/main/java/org/apache/iotdb/db/metrics/server/MetricsSystem.java
+++ b/server/src/main/java/org/apache/iotdb/db/metrics/server/MetricsSystem.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
  * agreements. See the NOTICE file distributed with this work for additional information regarding
  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
@@ -36,14 +36,6 @@ public class MetricsSystem {
     this.serverArgument = serverArgument;
   }
 
-  public ServerArgument getServerArgument() {
-    return serverArgument;
-  }
-
-  public void setServerArgument(ServerArgument serverArgument) {
-    this.serverArgument = serverArgument;
-  }
-
   public MetricRegistry getMetricRegistry() {
     return metricRegistry;
   }
@@ -55,23 +47,19 @@ public class MetricsSystem {
   public void start() {
     registerSource();
     registerSinks();
-    sinks.forEach(sink -> sink.start());
+    sinks.forEach(Sink::start);
   }
 
   public void stop() {
-    sinks.forEach(sink -> sink.stop());
-  }
-
-  public void report() {
-    sinks.forEach(sink -> sink.report());
+    sinks.forEach(Sink::stop);
   }
 
-  public void registerSource() {
+  private void registerSource() {
     MetricsSource source = new MetricsSource(serverArgument, metricRegistry);
     source.registerInfo();
     sources.add(source);
   }
 
-  public void registerSinks() {}
+  private void registerSinks() {}
 
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/metrics/server/QueryServlet.java b/server/src/main/java/org/apache/iotdb/db/metrics/server/QueryServlet.java
index 7a3812c..0788364 100644
--- a/server/src/main/java/org/apache/iotdb/db/metrics/server/QueryServlet.java
+++ b/server/src/main/java/org/apache/iotdb/db/metrics/server/QueryServlet.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
  * agreements. See the NOTICE file distributed with this work for additional information regarding
  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
@@ -28,16 +28,16 @@ public class QueryServlet extends HttpServlet {
 
   private static final long serialVersionUID = 1L;
 
-  private List<SqlArgument> list = TSServiceImpl.sqlArgumentsList;
   private MetricsPage page;
 
   public QueryServlet(MetricsPage page) {
     this.page = page;
+    List<SqlArgument> list = TSServiceImpl.sqlArgumentsList;
     this.page.setList(list);
   }
 
   @Override
-  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
     resp.setContentType("text/html;charset=utf-8");
     req.setCharacterEncoding("utf-8");
     resp.setStatus(HttpServletResponse.SC_OK);
diff --git a/server/src/main/java/org/apache/iotdb/db/metrics/server/ServerArgument.java b/server/src/main/java/org/apache/iotdb/db/metrics/server/ServerArgument.java
index 30f8b02..a4c9389 100644
--- a/server/src/main/java/org/apache/iotdb/db/metrics/server/ServerArgument.java
+++ b/server/src/main/java/org/apache/iotdb/db/metrics/server/ServerArgument.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
  * agreements. See the NOTICE file distributed with this work for additional information regarding
  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
@@ -23,6 +23,7 @@ import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 import java.util.StringTokenizer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -66,7 +67,7 @@ public class ServerArgument {
     } catch (UnknownHostException e) {
       logger.error("The host is unknow", e);
     }
-    return ia.getHostName();
+    return Objects.requireNonNull(ia).getHostName();
   }
 
   private String osName() {
@@ -75,8 +76,7 @@ public class ServerArgument {
 
   private int totalCores() {
     OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
-    int freeCores = osmxb.getAvailableProcessors();
-    return freeCores;
+    return osmxb.getAvailableProcessors();
   }
 
   private long totalMemory() {
@@ -93,20 +93,17 @@ public class ServerArgument {
 
   private long totalPhysicalMemory() {
     OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
-    long totalMemorySize = osmxb.getTotalPhysicalMemorySize() / 1024 / 1024;
-    return totalMemorySize;
+    return osmxb.getTotalPhysicalMemorySize() / 1024 / 1024;
   }
 
   private long usedPhysicalMemory() {
     OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
-    long usedMemorySize = (osmxb.getTotalPhysicalMemorySize() - osmxb.getFreePhysicalMemorySize()) / 1024 / 1024;
-    return usedMemorySize;
+    return (osmxb.getTotalPhysicalMemorySize() - osmxb.getFreePhysicalMemorySize()) / 1024 / 1024;
   }
 
   private long freePhysicalMemory() {
     OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
-    long freeMemorySize = osmxb.getFreePhysicalMemorySize() / 1024 / 1024;
-    return freeMemorySize;
+    return osmxb.getFreePhysicalMemorySize() / 1024 / 1024;
   }
 
   public int getPort() {
@@ -156,9 +153,9 @@ public class ServerArgument {
   public int getCpuRatio() {
     String osName = System.getProperty("os.name").toLowerCase();
     cpuRatio = 0;
-    if (osName.indexOf("windows") >= 0) {
+    if (osName.contains("windows")) {
       cpuRatio = getCpuRatioForWindows();
-    } else if (osName.indexOf("linux") >= 0) {
+    } else if (osName.contains("linux")) {
       cpuRatio = getCpuRateForLinux();
     } else {
       cpuRatio = 500;
@@ -175,16 +172,12 @@ public class ServerArgument {
       long[] c0 = readLinuxCpu();
       Thread.sleep(CPUTIME);
       long[] c1 = readLinuxCpu();
-      if (c0 != null && c1 != null) {
-        long idleCpuTime = c1[0] - c0[0];
-        long totalCpuTime = c1[1] - c0[1];
-        if (totalCpuTime == 0) {
-          return 100;
-        }
-        return (int)(100 * (1 - (double)idleCpuTime / totalCpuTime));
-      } else {
-        return 0;
+      long idleCpuTime = c1[0] - c0[0];
+      long totalCpuTime = c1[1] - c0[1];
+      if (totalCpuTime == 0) {
+        return 100;
       }
+      return (int)(100 * (1 - (double)idleCpuTime / totalCpuTime));
     } catch (Exception e) {
       logger.error("Get CPU Ratio failed", e);
       return 0;
@@ -243,7 +236,7 @@ public class ServerArgument {
         continue;
       }
       String cmd = line.substring(cmdidx, kmtidx).trim();
-      if (cmd.indexOf("wmic.exe") >= 0) {
+      if (cmd.contains("wmic.exe")) {
         continue;
       }
       String caption = line.substring(capidx, cmdidx).trim();
@@ -256,24 +249,24 @@ public class ServerArgument {
       if (caption.equals("System Idle Process") || caption.equals("System")) {
         if (s1.length() > 0) {
           if (!digitS1.get(0).equals("") && digitS1.get(0) != null) {
-            idletime += Long.valueOf(digitS1.get(0)).longValue();
+            idletime += Long.parseLong(digitS1.get(0));
           }
         }
         if (s2.length() > 0) {
           if (!digitS2.get(0).equals("") && digitS2.get(0) != null) {
-            idletime += Long.valueOf(digitS2.get(0)).longValue();
+            idletime += Long.parseLong(digitS2.get(0));
           }
         }
         continue;
       }
       if (s1.length() > 0) {
         if (!digitS1.get(0).equals("") && digitS1.get(0) != null) {
-          kneltime += Long.valueOf(digitS1.get(0)).longValue();
+          kneltime += Long.parseLong(digitS1.get(0));
         }
       }
       if (s2.length() > 0) {
         if (!digitS2.get(0).equals("") && digitS2.get(0) != null) {
-          kneltime += Long.valueOf(digitS2.get(0)).longValue();
+          kneltime += Long.parseLong(digitS2.get(0));
         }
       }
     }
@@ -288,15 +281,15 @@ public class ServerArgument {
    */
   private long[] readLinuxCpu() throws Exception {
     long[] retn = new long[2];
-    BufferedReader buffer = null;
+    BufferedReader buffer;
     long idleCpuTime = 0;
     long totalCpuTime = 0;
     buffer = new BufferedReader(new InputStreamReader(new FileInputStream("/proc/stat")));
-    String line = null;
+    String line;
     while ((line = buffer.readLine()) != null) {
       if (line.startsWith("cpu")) {
         StringTokenizer tokenizer = new StringTokenizer(line);
-        List<String> temp = new ArrayList<String>();
+        List<String> temp = new ArrayList<>();
         while (tokenizer.hasMoreElements()) {
           temp.add(tokenizer.nextToken());
         }
diff --git a/server/src/main/java/org/apache/iotdb/db/metrics/server/SqlArgument.java b/server/src/main/java/org/apache/iotdb/db/metrics/server/SqlArgument.java
index 5a294e3..ea7a276 100644
--- a/server/src/main/java/org/apache/iotdb/db/metrics/server/SqlArgument.java
+++ b/server/src/main/java/org/apache/iotdb/db/metrics/server/SqlArgument.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
  * agreements. See the NOTICE file distributed with this work for additional information regarding
  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
@@ -39,10 +39,6 @@ public class SqlArgument {
     return TSExecuteStatementResp;
   }
 
-  public void setTSExecuteStatementResp(TSExecuteStatementResp tSExecuteStatementResp) {
-    TSExecuteStatementResp = tSExecuteStatementResp;
-  }
-
   public long getStartTime() {
     return startTime;
   }
diff --git a/server/src/main/java/org/apache/iotdb/db/metrics/sink/ConsoleSink.java b/server/src/main/java/org/apache/iotdb/db/metrics/sink/ConsoleSink.java
index 7450a0a..1fa5f39 100644
--- a/server/src/main/java/org/apache/iotdb/db/metrics/sink/ConsoleSink.java
+++ b/server/src/main/java/org/apache/iotdb/db/metrics/sink/ConsoleSink.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
  * agreements. See the NOTICE file distributed with this work for additional information regarding
  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
@@ -20,11 +20,9 @@ import com.codahale.metrics.MetricRegistry;
 
 public class ConsoleSink implements Sink {
 
-  public MetricRegistry registry;
-  public ConsoleReporter reporter;
+  private ConsoleReporter reporter;
 
   public ConsoleSink(MetricRegistry registry) {
-    this.registry = registry;
     this.reporter = ConsoleReporter.forRegistry(registry).convertDurationsTo(TimeUnit.MILLISECONDS)
         .convertRatesTo(TimeUnit.SECONDS).build();
   }
diff --git a/server/src/main/java/org/apache/iotdb/db/metrics/sink/MetricsServletSink.java b/server/src/main/java/org/apache/iotdb/db/metrics/sink/MetricsServletSink.java
index a0528ac..c88e447 100644
--- a/server/src/main/java/org/apache/iotdb/db/metrics/sink/MetricsServletSink.java
+++ b/server/src/main/java/org/apache/iotdb/db/metrics/sink/MetricsServletSink.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
  * agreements. See the NOTICE file distributed with this work for additional information regarding
  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
@@ -23,7 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 
 public class MetricsServletSink implements Sink {
 
-  public MetricRegistry registry;
+  private MetricRegistry registry;
 
   public MetricsServletSink(MetricRegistry registry) {
     this.registry = registry;
diff --git a/server/src/main/java/org/apache/iotdb/db/metrics/sink/Sink.java b/server/src/main/java/org/apache/iotdb/db/metrics/sink/Sink.java
index d610c31..374bde4 100644
--- a/server/src/main/java/org/apache/iotdb/db/metrics/sink/Sink.java
+++ b/server/src/main/java/org/apache/iotdb/db/metrics/sink/Sink.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
  * agreements. See the NOTICE file distributed with this work for additional information regarding
  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
@@ -16,10 +16,10 @@ package org.apache.iotdb.db.metrics.sink;
 
 public interface Sink {
 
-  public void start();
+  void start();
 
-  public void stop();
+  void stop();
 
-  public void report();
+  void report();
 
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/metrics/source/JvmSource.java b/server/src/main/java/org/apache/iotdb/db/metrics/source/JvmSource.java
index 0b13fe6..d34f816 100644
--- a/server/src/main/java/org/apache/iotdb/db/metrics/source/JvmSource.java
+++ b/server/src/main/java/org/apache/iotdb/db/metrics/source/JvmSource.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
  * agreements. See the NOTICE file distributed with this work for additional information regarding
  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
@@ -22,8 +22,8 @@ import com.codahale.metrics.jvm.MemoryUsageGaugeSet;
 
 public class JvmSource implements Source {
 
-  public String sourceName = "jvm";
-  public MetricRegistry metricRegistry;
+  private String sourceName = "jvm";
+  private MetricRegistry metricRegistry;
 
   public JvmSource(MetricRegistry metricRegistry) {
     this.metricRegistry = metricRegistry;
diff --git a/server/src/main/java/org/apache/iotdb/db/metrics/source/MetricsSource.java b/server/src/main/java/org/apache/iotdb/db/metrics/source/MetricsSource.java
index 7eb911e..73ee743 100644
--- a/server/src/main/java/org/apache/iotdb/db/metrics/source/MetricsSource.java
+++ b/server/src/main/java/org/apache/iotdb/db/metrics/source/MetricsSource.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
  * agreements. See the NOTICE file distributed with this work for additional information regarding
  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
@@ -20,9 +20,9 @@ import com.codahale.metrics.MetricRegistry;
 
 public class MetricsSource implements Source {
 
-  public String sourceName = "iot-metrics";
-  public MetricRegistry metricRegistry;
-  public ServerArgument serverArgument;
+  private String sourceName = "iot-metrics";
+  private MetricRegistry metricRegistry;
+  private ServerArgument serverArgument;
 
   public MetricsSource(ServerArgument serverArgument, MetricRegistry metricRegistry) {
     this.serverArgument = serverArgument;
@@ -31,65 +31,35 @@ public class MetricsSource implements Source {
 
   public void registerInfo() {
 
-    metricRegistry.register(MetricRegistry.name(sourceName, "host"), new Gauge<String>() {
-      public String getValue() {
-        return serverArgument.getHost();
-      }
-    });
-
-    metricRegistry.register(MetricRegistry.name(sourceName, "port"), new Gauge<Integer>() {
-      public Integer getValue() {
-        return (int) serverArgument.getPort();
-      }
-    });
-
-    metricRegistry.register(MetricRegistry.name(sourceName, "cores"), new Gauge<Integer>() {
-      public Integer getValue() {
-        return (int) serverArgument.getCores();
-      }
-    });
-
-    metricRegistry.register(MetricRegistry.name(sourceName, "cpu_ratio"), new Gauge<Integer>() {
-      public Integer getValue() {
-        return (int) serverArgument.getCpuRatio();
-      }
-    });
-
-    metricRegistry.register(MetricRegistry.name(sourceName, "total_memory"), new Gauge<Integer>() {
-      public Integer getValue() {
-        return (int) serverArgument.getTotalMemory();
-      }
-    });
-
-    metricRegistry.register(MetricRegistry.name(sourceName, "max_memory"), new Gauge<Integer>() {
-      public Integer getValue() {
-        return (int) serverArgument.getMaxMemory();
-      }
-    });
-
-    metricRegistry.register(MetricRegistry.name(sourceName, "free_memory"), new Gauge<Integer>() {
-      public Integer getValue() {
-        return (int) serverArgument.getFreeMemory();
-      }
-    });
-
-    metricRegistry.register(MetricRegistry.name(sourceName, "totalPhysical_memory"), new Gauge<Integer>() {
-          public Integer getValue() {
-            return (int) serverArgument.getTotalPhysicalMemory();
-          }
-        });
-
-    metricRegistry.register(MetricRegistry.name(sourceName, "freePhysical_memory"), new Gauge<Integer>() {
-          public Integer getValue() {
-            return (int) serverArgument.getFreePhysicalMemory();
-          }
-        });
-
-    metricRegistry.register(MetricRegistry.name(sourceName, "usedPhysical_memory"), new Gauge<Integer>() {
-          public Integer getValue() {
-            return (int) serverArgument.getUsedPhysicalMemory();
-          }
-        });
+    metricRegistry.register(MetricRegistry.name(sourceName, "host"),
+        (Gauge<String>) () -> serverArgument.getHost());
+
+    metricRegistry.register(MetricRegistry.name(sourceName, "port"),
+        (Gauge<Integer>) () -> (int) serverArgument.getPort());
+
+    metricRegistry.register(MetricRegistry.name(sourceName, "cores"),
+        (Gauge<Integer>) () -> (int) serverArgument.getCores());
+
+    metricRegistry.register(MetricRegistry.name(sourceName, "cpu_ratio"),
+        (Gauge<Integer>) () -> (int) serverArgument.getCpuRatio());
+
+    metricRegistry.register(MetricRegistry.name(sourceName, "total_memory"),
+        (Gauge<Integer>) () -> (int) serverArgument.getTotalMemory());
+
+    metricRegistry.register(MetricRegistry.name(sourceName, "max_memory"),
+        (Gauge<Integer>) () -> (int) serverArgument.getMaxMemory());
+
+    metricRegistry.register(MetricRegistry.name(sourceName, "free_memory"),
+        (Gauge<Integer>) () -> (int) serverArgument.getFreeMemory());
+
+    metricRegistry.register(MetricRegistry.name(sourceName, "totalPhysical_memory"),
+        (Gauge<Integer>) () -> (int) serverArgument.getTotalPhysicalMemory());
+
+    metricRegistry.register(MetricRegistry.name(sourceName, "freePhysical_memory"),
+        (Gauge<Integer>) () -> (int) serverArgument.getFreePhysicalMemory());
+
+    metricRegistry.register(MetricRegistry.name(sourceName, "usedPhysical_memory"),
+        (Gauge<Integer>) () -> (int) serverArgument.getUsedPhysicalMemory());
   }
 
   @Override
diff --git a/server/src/main/java/org/apache/iotdb/db/metrics/source/Source.java b/server/src/main/java/org/apache/iotdb/db/metrics/source/Source.java
index 536b3db..a1f2663 100644
--- a/server/src/main/java/org/apache/iotdb/db/metrics/source/Source.java
+++ b/server/src/main/java/org/apache/iotdb/db/metrics/source/Source.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
  * agreements. See the NOTICE file distributed with this work for additional information regarding
  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
@@ -16,6 +16,6 @@ package org.apache.iotdb.db.metrics.source;
 
 public interface Source {
 
-  public String sourceName();
+  String sourceName();
 
 }
diff --git a/server/src/main/java/org/apache/iotdb/db/metrics/ui/MetricsPage.java b/server/src/main/java/org/apache/iotdb/db/metrics/ui/MetricsPage.java
index 6380150..33506c7 100644
--- a/server/src/main/java/org/apache/iotdb/db/metrics/ui/MetricsPage.java
+++ b/server/src/main/java/org/apache/iotdb/db/metrics/ui/MetricsPage.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
  * agreements. See the NOTICE file distributed with this work for additional information regarding
  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
@@ -22,6 +22,7 @@ import java.net.URL;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 import org.apache.iotdb.db.conf.IoTDBConstant;
 import org.apache.iotdb.db.metrics.server.SqlArgument;
 import org.apache.iotdb.service.rpc.thrift.TSExecuteStatementResp;
@@ -43,54 +44,59 @@ public class MetricsPage {
     this.list = list;
   }
 
-  public MetricsPage(MetricRegistry metricRegistry) {
+  MetricsPage(MetricRegistry metricRegistry) {
     this.mr = metricRegistry;
   }
 
   public String render() {
-    String html = "";
-    String tmpStr = "";
+    StringBuilder html = new StringBuilder();
+    String tmpStr;
     try {
       URL resource = MetricsPage.class.getClassLoader().getResource("iotdb/ui/static/index.html");
-      InputStream is = resource.openStream();
+      InputStream is = Objects.requireNonNull(resource).openStream();
       BufferedReader br = new BufferedReader(new InputStreamReader(is));
       while ((tmpStr = br.readLine()) != null) {
-        html += tmpStr;
+        html.append(tmpStr);
       }
       is.close();
     } catch (IOException e) {
       logger.error("Response page failed", e);
     }
-    html = html.replace("{version}", IoTDBConstant.VERSION);
+    html = new StringBuilder(html.toString().replace("{version}", IoTDBConstant.VERSION));
     
-    html = html.replace("{server}", mr.getGauges().get("iot-metrics.host").getValue() + ":"
-        + mr.getGauges().get("iot-metrics.port").getValue());
+    html = new StringBuilder(
+        html.toString().replace("{server}", mr.getGauges().get("iot-metrics.host").getValue() + ":"
+            + mr.getGauges().get("iot-metrics.port").getValue()));
     
     int cpuRatio = (int)mr.getGauges().get("iot-metrics.cpu_ratio").getValue();
     String os = System.getProperty("os.name");
     if(cpuRatio != 500) {
-      html = html.replace("{cpu}", mr.getGauges().get("iot-metrics.cores").getValue() + " Total, "
-          + cpuRatio + "% CPU Ratio");
+      html = new StringBuilder(html.toString()
+          .replace("{cpu}", mr.getGauges().get("iot-metrics.cores").getValue() + " Total, "
+              + cpuRatio + "% CPU Ratio"));
     } else {
-      html = html.replace("{cpu}", mr.getGauges().get("iot-metrics.cores").getValue() + " Total  "
-          + "<font color=\"red\">can't get the cpu ratio,because this OS:["+os+"] is not support</font>");
+      html = new StringBuilder(html.toString()
+          .replace("{cpu}", mr.getGauges().get("iot-metrics.cores").getValue() + " Total  "
+              + "<font color=\"red\">can't get the cpu ratio,because this OS:[" + os
+              + "] is not support</font>"));
     }
     
-    html = html.replace("{jvm_mem}",mr.getGauges().get("iot-metrics.max_memory").getValue() + "  "
-        + mr.getGauges().get("iot-metrics.total_memory").getValue() + "  "
-        + mr.getGauges().get("iot-metrics.free_memory").getValue() + " (Max/Total/Free)MB");
+    html = new StringBuilder(html.toString()
+        .replace("{jvm_mem}", mr.getGauges().get("iot-metrics.max_memory").getValue() + "  "
+            + mr.getGauges().get("iot-metrics.total_memory").getValue() + "  "
+            + mr.getGauges().get("iot-metrics.free_memory").getValue() + " (Max/Total/Free)MB"));
     
-    html = html.replace("{host_mem}",String.format("%.0f",
+    html = new StringBuilder(html.toString().replace("{host_mem}", String.format("%.0f",
         ((int) mr.getGauges().get("iot-metrics.totalPhysical_memory").getValue() / 1024.0))
-        + " GB Total,  "+ String.format("%.1f",
+        + " GB Total,  " + String.format("%.1f",
         ((int) mr.getGauges().get("iot-metrics.usedPhysical_memory").getValue() / 1024.0))
-        + " GB Used");
+        + " GB Used"));
     
-    html = html.replace("{sql_table}", sqlRow());
-    return html;
+    html = new StringBuilder(html.toString().replace("{sql_table}", sqlRow()));
+    return html.toString();
   }
 
-  public StringBuilder sqlRow() {
+  private StringBuilder sqlRow() {
     StringBuilder table = new StringBuilder();
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS");
     SqlArgument sqlArgument;
@@ -113,27 +119,21 @@ public class MetricsPage {
         status = "FAILED";
       }
 
-      table.append(
-          "<tr>"
-          + "<td>" + resp.getOperationType() + "</td>"
-          + "<td>" + sdf.format(new Date(sqlArgument.getStartTime())) + "</td>"
-          + "<td>" + sdf.format(new Date(sqlArgument.getEndTime())) + "</td>"
-          + "<td>" + (int) (sqlArgument.getEndTime() - sqlArgument.getStartTime()) + " ms</td>"
-          + "<td class=\"sql\">" + sqlArgument.getStatement() + "</td>"
-          + "<td>" + status + "</td>"
-          + "<td>" + (errMsg.equals("") ? "== Parsed Physical Plan ==" : errMsg)
-          +   "<span class=\"expand-details\" onclick=\"this.parentNode.querySelector('.stacktrace-details').classList.toggle('collapsed')\">+ details</span>"
-          +   "<div class=\"stacktrace-details collapsed\">"
-          +     "<pre>"
-          +       "Physical Plan: " + sqlArgument.getPlan().getClass().getSimpleName()
-          +       "</br>===========================</br>"
-          +       "OperatorType: " + sqlArgument.getPlan().getOperatorType()
-          +       "</br>===========================</br>"
-          +       "Path: " + sqlArgument.getPlan().getPaths().toString()
-          +     "</pre>"
-          +   "</div>"
-          + "</td>"
-          +"</tr>");
+      table.append("<tr>" + "<td>").append(resp.getOperationType()).append("</td>").append("<td>")
+          .append(sdf.format(new Date(sqlArgument.getStartTime()))).append("</td>").append("<td>")
+          .append(sdf.format(new Date(sqlArgument.getEndTime()))).append("</td>").append("<td>")
+          .append((int) (sqlArgument.getEndTime() - sqlArgument.getStartTime())).append(" ms</td>")
+          .append("<td class=\"sql\">").append(sqlArgument.getStatement()).append("</td>")
+          .append("<td>").append(status).append("</td>").append("<td>")
+          .append(errMsg.equals("") ? "== Parsed Physical Plan ==" : errMsg).append(
+          "<span class=\"expand-details\" onclick=\"this.parentNode.querySelector('.stacktrace-details').classList.toggle('collapsed')\">+ details</span>")
+          .append("<div class=\"stacktrace-details collapsed\">").append("<pre>")
+          .append("Physical Plan: ").append(sqlArgument.getPlan().getClass().getSimpleName())
+          .append("</br>===========================</br>").append("OperatorType: ")
+          .append(sqlArgument.getPlan().getOperatorType())
+          .append("</br>===========================</br>").append("Path: ")
+          .append(sqlArgument.getPlan().getPaths().toString()).append("</pre>").append("</div>")
+          .append("</td>").append("</tr>");
     }
     return table;
   }
diff --git a/server/src/main/java/org/apache/iotdb/db/metrics/ui/MetricsWebUI.java b/server/src/main/java/org/apache/iotdb/db/metrics/ui/MetricsWebUI.java
index f761dbe..fb52267 100644
--- a/server/src/main/java/org/apache/iotdb/db/metrics/ui/MetricsWebUI.java
+++ b/server/src/main/java/org/apache/iotdb/db/metrics/ui/MetricsWebUI.java
@@ -1,4 +1,4 @@
-/**
+/*
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
  * agreements. See the NOTICE file distributed with this work for additional information regarding
  * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
@@ -31,27 +31,15 @@ public class MetricsWebUI {
     this.metricRegistry = metricRegistry;
   }
 
-  public MetricRegistry getMetricRegistry() {
-    return metricRegistry;
-  }
-
-  public void setMetricRegistry(MetricRegistry metricRegistry) {
-    this.metricRegistry = metricRegistry;
-  }
-
   public List<ServletContextHandler> getHandlers() {
     return handlers;
   }
 
-  public void setHandlers(List<ServletContextHandler> handlers) {
-    this.handlers = handlers;
-  }
-
   public void initialize() {
     MetricsPage masterPage = new MetricsPage(metricRegistry);
     QueryServlet queryServlet = new QueryServlet(masterPage);
     ServletContextHandler staticHandler = JettyUtil.createStaticHandler();
-    ServletContextHandler queryHandler = JettyUtil.createServletHandler("/",queryServlet);
+    ServletContextHandler queryHandler = JettyUtil.createServletHandler("/",queryServlet, "/");
     handlers.add(staticHandler);
     handlers.add(queryHandler);
   }
diff --git a/server/src/main/java/org/apache/iotdb/db/service/MetricsService.java b/server/src/main/java/org/apache/iotdb/db/service/MetricsService.java
index e3c9ff5..e2b6e22 100644
--- a/server/src/main/java/org/apache/iotdb/db/service/MetricsService.java
+++ b/server/src/main/java/org/apache/iotdb/db/service/MetricsService.java
@@ -172,7 +172,7 @@ public class MetricsService implements MetricsServiceMBean, IService {
 
     private Server server;
 
-    public MetricsServiceThread(Server server) {
+    MetricsServiceThread(Server server) {
       this.server = server;
     }