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

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-pack.git

commit c79c6ecdb09ce51b32b383fb0aa81870214ac903
Author: Lei Zhang <[email protected]>
AuthorDate: Thu Aug 8 09:43:08 2019 +0800

    SCB-1411 Implement dashboard system info card
---
 alpha/alpha-ui/pom.xml                             |  4 +
 .../servicecomb/pack/alpha/ui/IndexController.java | 53 +++++++++++-
 .../pack/alpha/ui/vo/SystemInfoDTO.java            | 93 ++++++++++++++++++++
 .../src/main/resources/templates/index.html        | 99 +++++++++++++++++++++-
 4 files changed, 247 insertions(+), 2 deletions(-)

diff --git a/alpha/alpha-ui/pom.xml b/alpha/alpha-ui/pom.xml
index 85457f2..ac995ac 100644
--- a/alpha/alpha-ui/pom.xml
+++ b/alpha/alpha-ui/pom.xml
@@ -90,6 +90,10 @@
     <!-- spring boot -->
     <dependency>
       <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-actuator</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-thymeleaf</artifactId>
     </dependency>
     <dependency>
diff --git 
a/alpha/alpha-ui/src/main/java/org/apache/servicecomb/pack/alpha/ui/IndexController.java
 
b/alpha/alpha-ui/src/main/java/org/apache/servicecomb/pack/alpha/ui/IndexController.java
index 21daa9d..cfb0c68 100644
--- 
a/alpha/alpha-ui/src/main/java/org/apache/servicecomb/pack/alpha/ui/IndexController.java
+++ 
b/alpha/alpha-ui/src/main/java/org/apache/servicecomb/pack/alpha/ui/IndexController.java
@@ -17,6 +17,12 @@
 
 package org.apache.servicecomb.pack.alpha.ui;
 
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import org.apache.servicecomb.pack.alpha.ui.vo.SystemInfoDTO;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.actuate.metrics.MetricsEndpoint;
+import org.springframework.boot.actuate.metrics.MetricsEndpoint.Sample;
 import org.springframework.boot.web.servlet.error.ErrorController;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
@@ -26,9 +32,13 @@ import org.springframework.web.bind.annotation.RequestParam;
 @Controller
 public class IndexController implements ErrorController {
 
+  @Autowired
+  MetricsEndpoint metricsEndpoint;
+
   // index
   @GetMapping("/admin")
-  public String index() {
+  public String index(ModelMap map) {
+    map.put("systemInfo",getSystemInfo());
     return "index";
   }
 
@@ -57,4 +67,45 @@ public class IndexController implements ErrorController {
   public String getErrorPath() {
     return "/error";
   }
+
+  private SystemInfoDTO getSystemInfo() {
+    SystemInfoDTO systemInfoDTO = new SystemInfoDTO();
+
+    //uptime
+    long startTime = metricsEndpoint.metric("process.start.time", 
null).getMeasurements().get(0)
+        .getValue().longValue();
+    long seconds = System.currentTimeMillis() / 1000 - startTime;
+    int day = (int) TimeUnit.SECONDS.toDays(seconds);
+    long hours = TimeUnit.SECONDS.toHours(seconds) - (day * 24);
+    long minute = TimeUnit.SECONDS.toMinutes(seconds) - 
(TimeUnit.SECONDS.toHours(seconds) * 60);
+    long second = TimeUnit.SECONDS.toSeconds(seconds) - 
(TimeUnit.SECONDS.toMinutes(seconds) * 60);
+    systemInfoDTO.setUpTime(String.format("%dd %dh %dm %ds", day, hours, 
minute, second));
+
+    //cpus
+    systemInfoDTO.setCpus(
+        metricsEndpoint.metric("system.cpu.count", 
null).getMeasurements().get(0).getValue()
+            .intValue());
+
+    //system load
+    systemInfoDTO.setSystemLoad(Math.round(
+        metricsEndpoint.metric("system.load.average.1m", 
null).getMeasurements().get(0).getValue()
+            .floatValue() * 100) / 100);
+
+    //thread
+    systemInfoDTO.setThreadsLive(
+        metricsEndpoint.metric("jvm.threads.live", 
null).getMeasurements().get(0).getValue()
+            .intValue());
+    systemInfoDTO.setThreadsDaemon(
+        metricsEndpoint.metric("jvm.threads.daemon", 
null).getMeasurements().get(0).getValue()
+            .intValue());
+    systemInfoDTO.setThreadsPeak(
+        metricsEndpoint.metric("jvm.threads.peak", 
null).getMeasurements().get(0).getValue()
+            .intValue());
+
+    //gc
+    List<Sample> samples = metricsEndpoint.metric("jvm.gc.pause", 
null).getMeasurements();
+    systemInfoDTO.setGcCount(samples.get(0).getValue().intValue());
+    systemInfoDTO.setGcTime(samples.get(1).getValue().floatValue());
+    return systemInfoDTO;
+  }
 }
diff --git 
a/alpha/alpha-ui/src/main/java/org/apache/servicecomb/pack/alpha/ui/vo/SystemInfoDTO.java
 
b/alpha/alpha-ui/src/main/java/org/apache/servicecomb/pack/alpha/ui/vo/SystemInfoDTO.java
new file mode 100644
index 0000000..7ce1e2e
--- /dev/null
+++ 
b/alpha/alpha-ui/src/main/java/org/apache/servicecomb/pack/alpha/ui/vo/SystemInfoDTO.java
@@ -0,0 +1,93 @@
+/*
+ * 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.servicecomb.pack.alpha.ui.vo;
+
+public class SystemInfoDTO {
+  private String upTime;
+  private int cpus;
+  private float systemLoad;
+  private long threadsLive;
+  private long threadsDaemon;
+  private long threadsPeak;
+  private long gcCount;
+  private float gcTime;
+
+  public String getUpTime() {
+    return upTime;
+  }
+
+  public void setUpTime(String upTime) {
+    this.upTime = upTime;
+  }
+
+  public int getCpus() {
+    return cpus;
+  }
+
+  public void setCpus(int cpus) {
+    this.cpus = cpus;
+  }
+
+  public float getSystemLoad() {
+    return systemLoad;
+  }
+
+  public void setSystemLoad(float systemLoad) {
+    this.systemLoad = systemLoad;
+  }
+
+  public long getThreadsLive() {
+    return threadsLive;
+  }
+
+  public void setThreadsLive(long threadsLive) {
+    this.threadsLive = threadsLive;
+  }
+
+  public long getThreadsDaemon() {
+    return threadsDaemon;
+  }
+
+  public void setThreadsDaemon(long threadsDaemon) {
+    this.threadsDaemon = threadsDaemon;
+  }
+
+  public long getThreadsPeak() {
+    return threadsPeak;
+  }
+
+  public void setThreadsPeak(long threadsPeak) {
+    this.threadsPeak = threadsPeak;
+  }
+
+  public long getGcCount() {
+    return gcCount;
+  }
+
+  public void setGcCount(long gcCount) {
+    this.gcCount = gcCount;
+  }
+
+  public float getGcTime() {
+    return gcTime;
+  }
+
+  public void setGcTime(float gcTime) {
+    this.gcTime = gcTime;
+  }
+}
diff --git a/alpha/alpha-ui/src/main/resources/templates/index.html 
b/alpha/alpha-ui/src/main/resources/templates/index.html
index 5ed8b7f..23be161 100644
--- a/alpha/alpha-ui/src/main/resources/templates/index.html
+++ b/alpha/alpha-ui/src/main/resources/templates/index.html
@@ -115,7 +115,7 @@
         </div>
       </div>
 
-      <!-- Top Chart -->
+      <!-- Slow Transaction Top N  -->
       <div class="col-xl-4 col-lg-5">
         <div class="card shadow mb-4">
           <div class="card-header py-3 d-flex flex-row align-items-center 
justify-content-between">
@@ -129,6 +129,103 @@
         </div>
       </div>
     </div>
+
+    <div class="row">
+
+      <!-- Health Chart -->
+      <div class="col-xl-8 col-lg-7">
+        <div class="card shadow mb-4">
+          <div class="card-header py-3 d-flex flex-row align-items-center 
justify-content-between">
+            <h6 class="m-0 font-weight-bold text-primary">Health Overview</h6>
+          </div>
+          <!-- Card Body -->
+          <div class="card-body">
+            <div class="chart-area">
+              <canvas></canvas>
+            </div>
+          </div>
+        </div>
+      </div>
+
+      <!-- Info Card  -->
+      <div class="col-xl-4 col-lg-5">
+        <div class="card shadow mb-4">
+          <div class="card-header py-3 d-flex flex-row align-items-center 
justify-content-between">
+            <h6 class="m-0 font-weight-bold text-primary">System Info</h6>
+          </div>
+          <!-- Card Body -->
+          <div class="card-body">
+            <div class="row">
+              <div class="col-xl-5 col-lg-5">
+                <div class="mb-1 small">UPTIME</div>
+              </div>
+              <div class="col-xl-7 col-lg-7">
+                <div class="mb-1 small" th:text="${systemInfo.upTime}"></div>
+              </div>
+            </div>
+            <div class="row">
+              <div class="col-xl-5 col-lg-5">
+                <div class="mb-1 small">CPUS</div>
+              </div>
+              <div class="col-xl-7 col-lg-7">
+                <div class="mb-1 small" th:text="${systemInfo.cpus}"></div>
+              </div>
+            </div>
+            <div class="row">
+              <div class="col-xl-5 col-lg-5">
+                <div class="mb-1 small">SYSTEM LOAD</div>
+              </div>
+              <div class="col-xl-7 col-lg-7">
+                <div class="mb-1 small" 
th:text="${systemInfo.systemLoad}"></div>
+              </div>
+            </div>
+            <hr/>
+            <div class="row">
+              <div class="col-xl-5 col-lg-5">
+                <div class="mb-1 small">THREAD LIVE</div>
+              </div>
+              <div class="col-xl-7 col-lg-7">
+                <div class="mb-1 small" 
th:text="${systemInfo.threadsLive}"></div>
+              </div>
+            </div>
+            <div class="row">
+              <div class="col-xl-5 col-lg-5">
+                <div class="mb-1 small">THREAD DAEMON</div>
+              </div>
+              <div class="col-xl-7 col-lg-7">
+                <div class="mb-1 small" 
th:text="${systemInfo.threadsDaemon}"></div>
+              </div>
+            </div>
+            <div class="row">
+              <div class="col-xl-5 col-lg-5">
+                <div class="mb-1 small">THREAD PEAK</div>
+              </div>
+              <div class="col-xl-7 col-lg-7">
+                <div class="mb-1 small" 
th:text="${systemInfo.threadsPeak}"></div>
+              </div>
+            </div>
+            <hr/>
+            <div class="row">
+              <div class="col-xl-5 col-lg-5">
+                <div class="mb-1 small">GC COUNT</div>
+              </div>
+              <div class="col-xl-7 col-lg-7">
+                <div class="mb-1 small" th:text="${systemInfo.gcCount}"></div>
+              </div>
+            </div>
+            <div class="row">
+              <div class="col-xl-5 col-lg-5">
+                <div class="mb-1 small">GC TIME</div>
+              </div>
+              <div class="col-xl-7 col-lg-7">
+                <div class="mb-1 small" th:text="${systemInfo.gcTime} + ' 
sec'"></div>
+              </div>
+            </div>
+          </div>
+        </div>
+      </div>
+    </div>
+
   </div>
   <div layout:fragment="scripts">
     <script th:src="@{/js/alpha-dashboard.js}"></script>

Reply via email to