mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2026-04-23 13:25:18 +08:00
服务列表页带宽使用比特代替字节
This commit is contained in:
@@ -42,6 +42,24 @@ func FormatBytes(bytes int64) string {
|
||||
}
|
||||
}
|
||||
|
||||
func FormatBits(bits int64) string {
|
||||
if bits < Pow1024(1) {
|
||||
return FormatInt64(bits) + "Bps"
|
||||
} else if bits < Pow1024(2) {
|
||||
return fmt.Sprintf("%.4fKBps", float64(bits)/float64(Pow1024(1)))
|
||||
} else if bits < Pow1024(3) {
|
||||
return fmt.Sprintf("%.4fMBps", float64(bits)/float64(Pow1024(2)))
|
||||
} else if bits < Pow1024(4) {
|
||||
return fmt.Sprintf("%.4fGBps", float64(bits)/float64(Pow1024(3)))
|
||||
} else if bits < Pow1024(5) {
|
||||
return fmt.Sprintf("%.4fTBps", float64(bits)/float64(Pow1024(4)))
|
||||
} else if bits < Pow1024(6) {
|
||||
return fmt.Sprintf("%.4fPBps", float64(bits)/float64(Pow1024(5)))
|
||||
} else {
|
||||
return fmt.Sprintf("%.4fEBps", float64(bits)/float64(Pow1024(6)))
|
||||
}
|
||||
}
|
||||
|
||||
func FormatCount(count int64) string {
|
||||
if count < 1000 {
|
||||
return types.String(count)
|
||||
|
||||
@@ -3,7 +3,6 @@ package servers
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/utils/numberutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
@@ -225,9 +224,9 @@ func (this *IndexAction) RunGet(params struct {
|
||||
}
|
||||
|
||||
// 统计数据
|
||||
var bandwidth = ""
|
||||
var bandwidthBits int64 = 0
|
||||
if server.BandwidthBytes > 0 {
|
||||
bandwidth = numberutils.FormatBytes(server.BandwidthBytes)
|
||||
bandwidthBits = server.BandwidthBytes * 8
|
||||
}
|
||||
|
||||
serverMaps = append(serverMaps, maps.Map{
|
||||
@@ -247,7 +246,7 @@ func (this *IndexAction) RunGet(params struct {
|
||||
"auditingIsOk": auditingIsOk,
|
||||
"user": userMap,
|
||||
"auditingTime": auditingTime,
|
||||
"bandwidth": bandwidth,
|
||||
"bandwidthBits": bandwidthBits,
|
||||
})
|
||||
}
|
||||
this.Data["servers"] = serverMaps
|
||||
|
||||
Reference in New Issue
Block a user