Browse Source

fix cpu usage record

0xJacky 3 years ago
parent
commit
41b331ab11
2 changed files with 4 additions and 2 deletions
  1. 2 2
      frontend/src/views/dashboard/DashBoard.vue
  2. 2 0
      server/tool/cpu_usage.go

+ 2 - 2
frontend/src/views/dashboard/DashBoard.vue

@@ -127,8 +127,8 @@ export default {
         this.websocket.onmessage = this.wsOnMessage
         this.websocket.onopen = this.wsOpen
         this.$api.analytic.cpu_usage().then(r => {
-            this.cpu_analytic.datasets[0].data.concat(r.user)
-            this.cpu_analytic.datasets[1].data.concat(r.total)
+            this.cpu_analytic.datasets[0].data = this.cpu_analytic.datasets[0].data.concat(r.user)
+            this.cpu_analytic.datasets[1].data = this.cpu_analytic.datasets[1].data.concat(r.total)
         })
     },
     destroyed() {

+ 2 - 0
server/tool/cpu_usage.go

@@ -22,7 +22,9 @@ func RecordCpuUsage() {
 		threadNum := runtime.GOMAXPROCS(0)
 
 		cpuUserUsage := (cpuTimesAfter[0].User - cpuTimesBefore[0].User) / (float64(1000*threadNum) / 1000)
+		cpuUserUsage *= 100
 		cpuSystemUsage := (cpuTimesAfter[0].System - cpuTimesBefore[0].System) / (float64(1000*threadNum) / 1000)
+		cpuSystemUsage *= 100
 		now := time.Now()
 		u := cpuUsage{
 			Time:  now,