调整 网速统计 避免因长时间处于后台导致 js计时器挂起 计时不准导致统计数据异常
This commit is contained in:
parent
079a556e7a
commit
b8bcf1b3c0
@ -2,6 +2,7 @@ import {computed, reactive, ref, toRefs, toValue} from "vue";
|
||||
import {net} from "frontend/wailsjs/go/models";
|
||||
import IOCountersStat = net.IOCountersStat;
|
||||
import {GetNetworkCounter} from "frontend/wailsjs/go/system/InfoUtils";
|
||||
import moment from "moment";
|
||||
|
||||
const network = reactive({
|
||||
counter: {
|
||||
@ -21,6 +22,7 @@ const network = reactive({
|
||||
bytesRecv: -1,
|
||||
bytesSent: -1
|
||||
},
|
||||
lastTimestamp: 0,
|
||||
interval: <NodeJS.Timeout|undefined>undefined,
|
||||
}
|
||||
})
|
||||
@ -30,20 +32,24 @@ function loopNetworkSumCounter(){
|
||||
clearInterval(network.sumCounter.interval)
|
||||
function loop(){
|
||||
GetNetworkCounter(true).then(result=> {
|
||||
let now = moment()
|
||||
let recv = result[0].bytesRecv || 0
|
||||
let sent = result[0].bytesSent || 0
|
||||
|
||||
network.sumCounter.data.bytesRecv = network.sumCounter.data.bytesRecv == -1?recv:network.sumCounter.data.bytesRecv
|
||||
network.sumCounter.data.bytesSent = network.sumCounter.data.bytesSent == -1?sent:network.sumCounter.data.bytesSent
|
||||
|
||||
// 实时网速
|
||||
network.sumCounter.rate.recv = recv - network.sumCounter.data.bytesRecv
|
||||
network.sumCounter.rate.sent = sent - network.sumCounter.data.bytesSent
|
||||
|
||||
network.sumCounter.rate.max.recv = Math.max(network.sumCounter.rate.max.recv, network.sumCounter.rate.recv)
|
||||
network.sumCounter.rate.max.sent = Math.max(network.sumCounter.rate.max.sent, network.sumCounter.rate.sent)
|
||||
if(now.diff(moment.unix(network.sumCounter.lastTimestamp),'s') <= 1){
|
||||
// 实时网速
|
||||
network.sumCounter.rate.recv = recv - network.sumCounter.data.bytesRecv
|
||||
network.sumCounter.rate.sent = sent - network.sumCounter.data.bytesSent
|
||||
network.sumCounter.rate.max.recv = Math.max(network.sumCounter.rate.max.recv, network.sumCounter.rate.recv)
|
||||
network.sumCounter.rate.max.sent = Math.max(network.sumCounter.rate.max.sent, network.sumCounter.rate.sent)
|
||||
}
|
||||
|
||||
network.sumCounter.data = result[0]
|
||||
|
||||
network.sumCounter.lastTimestamp = now.unix()
|
||||
})
|
||||
|
||||
// 每秒调用一次
|
||||
|
@ -1,6 +1,8 @@
|
||||
package system
|
||||
|
||||
import "github.com/shirou/gopsutil/net"
|
||||
import (
|
||||
"github.com/shirou/gopsutil/net"
|
||||
)
|
||||
|
||||
func (i *InfoUtils) GetNetWorkConnection() []net.ConnectionStat {
|
||||
info, _ := net.Connections("all")
|
||||
|
Loading…
Reference in New Issue
Block a user