add SI bytes TXRX
This commit is contained in:
parent
151de953b5
commit
9068c861f5
@ -102,6 +102,8 @@ func GenerateReport(dev *wgtypes.Device, conf *DsnetConfig, oldReport *DsnetRepo
|
|||||||
LastHandshakeTime: wgPeer.LastHandshakeTime,
|
LastHandshakeTime: wgPeer.LastHandshakeTime,
|
||||||
ReceiveBytes: wgPeer.ReceiveBytes,
|
ReceiveBytes: wgPeer.ReceiveBytes,
|
||||||
TransmitBytes: wgPeer.TransmitBytes,
|
TransmitBytes: wgPeer.TransmitBytes,
|
||||||
|
ReceiveBytesSI: BytesToSI(wgPeer.ReceiveBytes),
|
||||||
|
TransmitBytesSI: BytesToSI(wgPeer.TransmitBytes),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,4 +163,6 @@ type PeerReport struct {
|
|||||||
LastHandshakeTime time.Time
|
LastHandshakeTime time.Time
|
||||||
ReceiveBytes int64
|
ReceiveBytes int64
|
||||||
TransmitBytes int64
|
TransmitBytes int64
|
||||||
|
ReceiveBytesSI string
|
||||||
|
TransmitBytesSI string
|
||||||
}
|
}
|
||||||
|
14
util.go
14
util.go
@ -48,3 +48,17 @@ func ConfirmOrAbort(format string, a ...interface{}) {
|
|||||||
ExitFail("Aborted.")
|
ExitFail("Aborted.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BytesToSI(b int64) string {
|
||||||
|
const unit = 1000
|
||||||
|
if b < unit {
|
||||||
|
return fmt.Sprintf("%d B", b)
|
||||||
|
}
|
||||||
|
div, exp := int64(unit), 0
|
||||||
|
for n := b / unit; n >= unit; n /= unit {
|
||||||
|
div *= unit
|
||||||
|
exp++
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("%.1f %cB",
|
||||||
|
float64(b)/float64(div), "kMGTPE"[exp])
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user