11<script setup>
2- import {computed , onMounted , ref } from " vue" ;
2+ import {computed , onMounted , provide , ref } from " vue" ;
33import moment from ' moment'
44import CPU from " @/components/CPU.vue" ;
55import Mem from " @/components/Mem.vue" ;
@@ -32,6 +32,8 @@ const handleChangeDark = () => {
3232const area = ref ([])
3333const selectArea = ref (' all' )
3434
35+ const type = ref (' all' )
36+
3537const data = ref ([])
3638
3739const selectHost = ref (' ' )
@@ -47,25 +49,42 @@ const host = computed(() => {
4749 if (selectArea .value === ' all' ) {
4850 return data .value
4951 }
52+
5053 return data .value .filter (item => item .Host .Name .slice (0 , 2 ) === selectArea .value )
5154})
5255
56+ const hosts = computed (() => {
57+ if (type .value === ' all' ) {
58+ return host .value
59+ } else if (type .value === ' online' ) {
60+ return host .value .filter (item => item .status )
61+ } else {
62+ return host .value .filter (item => ! item .status )
63+ }
64+ })
65+
5366const stats = computed (() => {
5467 const online = host .value .filter (item => item .status )
5568 let bandwidth_up = 0
5669 let bandwidth_down = 0
70+ let traffic_up = 0
71+ let traffic_down = 0
5772
5873 host .value .forEach ((item ) => {
59- bandwidth_up += item .State .NetInSpeed
60- bandwidth_down += item .State .NetOutSpeed
74+ bandwidth_up += item .State .NetOutSpeed
75+ bandwidth_down += item .State .NetInSpeed
76+ traffic_up += item .State .NetOutTransfer
77+ traffic_down += item .State .NetInTransfer
6178 })
6279
6380 return {
6481 total: host .value .length ,
6582 online: online .length ,
6683 offline: host .value .length - online .length ,
6784 bandwidth_up: bandwidth_up,
68- bandwidth_down: bandwidth_down
85+ bandwidth_down: bandwidth_down,
86+ traffic_up: traffic_up,
87+ traffic_down: traffic_down
6988 }
7089})
7190
@@ -105,7 +124,7 @@ const initScoket = async () => {
105124 }
106125 }
107126
108- if (charts .value [host .Host .Name ].cpu .length == 60 ) {
127+ if (charts .value [host .Host .Name ].cpu .length == 2 ) {
109128 charts .value [host .Host .Name ].cpu = charts .value [host .Host .Name ].cpu .slice (1 )
110129 charts .value [host .Host .Name ].mem = charts .value [host .Host .Name ].mem .slice (1 )
111130 charts .value [host .Host .Name ].net_in = charts .value [host .Host .Name ].net_in .slice (1 )
@@ -160,7 +179,7 @@ const progressStatus = (value) => {
160179 } else if (value < 90 ) {
161180 return ' warning' ;
162181 } else {
163- return ' error ' ;
182+ return ' danger ' ;
164183 }
165184}
166185
@@ -207,6 +226,11 @@ const handleClose = () => {
207226 deleteVisible .value = false
208227}
209228
229+ const handleChangeType = (value ) => {
230+ type .value = value
231+ }
232+
233+ provide (' handleChangeType' , handleChangeType)
210234
211235 </script >
212236
@@ -235,9 +259,9 @@ const handleClose = () => {
235259 <span :class =" `flag-icon flag-icon-${item.replace('UK', 'GB').toLowerCase()}`" style =" margin-right : 3px ;" ></span > {{item}}
236260 </div >
237261 </div >
238- <StatsCard :stats =" stats" />
262+ <StatsCard :type = " type " : stats =" stats" @handleChangeType = " handleChangeType " />
239263 <div class =" monitor-card" >
240- <div class =" monitor-item" :class =" selectHost === item.Host.Name ? 'is-active' : ''" v-for =" (item, index) in host " @click =" handleSelectHost(item.Host.Name)" :key =" index" >
264+ <div class =" monitor-item" :class =" selectHost === item.Host.Name ? 'is-active' : ''" v-for =" (item, index) in hosts " @click =" handleSelectHost(item.Host.Name)" :key =" index" >
241265 <div class =" name" >
242266 <div class =" title" >
243267 <span :class =" `flag-icon flag-icon-${item.Host.Name.slice(0, 2).replace('UK', 'GB').toLowerCase()}`" ></span >
@@ -262,6 +286,11 @@ const handleClose = () => {
262286 <div class =" monitor-item-value" >{{(item.State.MemUsed / item.Host.MemTotal * 100).toFixed(2) + '%'}}</div >
263287 <a-progress class =" monitor-item-progress" :status =" progressStatus(item.State.MemUsed / item.Host.MemTotal * 100)" :percent =" item.State.MemUsed / item.Host.MemTotal" :show-text =" false" style =" width : 60px " />
264288 </div >
289+ <div class =" mem" >
290+ <div class =" monitor-item-title" >虚拟内存(Swap)</div >
291+ <div class =" monitor-item-value" >{{item.Host.SwapTotal === 0 ? (0).toFixed(2)+'%' : (item.State.SwapUsed / item.Host.SwapTotal * 100).toFixed(2) + '%'}}</div >
292+ <a-progress class =" monitor-item-progress" :status =" progressStatus(item.State.SwapUsed / item.Host.SwapTotal * 100)" :percent =" item.Host.SwapTotal === 0 ? (0) : (item.State.SwapUsed / item.Host.SwapTotal)" :show-text =" false" style =" width : 60px " />
293+ </div >
265294 <div class =" network" >
266295 <div class =" monitor-item-title" >网络速度(IN|OUT)</div >
267296 <div class =" monitor-item-value" >{{`${formatBytes(item.State.NetInSpeed)}/s | ${formatBytes(item.State.NetOutSpeed)}/s`}}</div >
@@ -315,7 +344,7 @@ const handleClose = () => {
315344 </div >
316345 <div class =" detail-item" >
317346 <div class =" name" >虚拟内存(Swap)</div >
318- <div class =" value" >{{formatBytes(item.State.SwapUsed)}}</div >
347+ <div class =" value" >{{formatBytes(item.State.SwapUsed)}} / {{formatBytes(item.Host.SwapTotal)}} </div >
319348 </div >
320349 <div class =" detail-item" >
321350 <div class =" name" >网络速度(IN|OUT)</div >
@@ -327,7 +356,7 @@ const handleClose = () => {
327356 </div >
328357 <div class =" detail-item" >
329358 <div class =" name" >流量使用↑|↓</div >
330- <div class =" value" >{{formatBytes(item.State.NetInTransfer )}} | {{formatBytes(item.State.NetOutTransfer )}}</div >
359+ <div class =" value" >{{formatBytes(item.State.NetOutTransfer )}} | {{formatBytes(item.State.NetInTransfer )}}</div >
331360 </div >
332361 <div class =" detail-item" >
333362 <div class =" name" >开机时间</div >
0 commit comments