添加展示多硬盘用量信息的功能 (#1747)

* featurel: 添加多磁盘用量信息展示
This commit is contained in:
Juneyx
2024-05-18 11:52:44 +08:00
committed by GitHub
parent 42de9257c3
commit fb53d639be
5 changed files with 58 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
package utils
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"runtime"
"time"
@@ -20,7 +21,7 @@ type Server struct {
Os Os `json:"os"`
Cpu Cpu `json:"cpu"`
Ram Ram `json:"ram"`
Disk Disk `json:"disk"`
Disk []Disk `json:"disk"`
}
type Os struct {
@@ -43,6 +44,7 @@ type Ram struct {
}
type Disk struct {
MountPoint string `json:"mountPoint"`
UsedMB int `json:"usedMb"`
UsedGB int `json:"usedGb"`
TotalMB int `json:"totalMb"`
@@ -104,15 +106,21 @@ func InitRAM() (r Ram, err error) {
//@description: 硬盘信息
//@return: d Disk, err error
func InitDisk() (d Disk, err error) {
if u, err := disk.Usage("/"); err != nil {
return d, err
} else {
d.UsedMB = int(u.Used) / MB
d.UsedGB = int(u.Used) / GB
d.TotalMB = int(u.Total) / MB
d.TotalGB = int(u.Total) / GB
d.UsedPercent = int(u.UsedPercent)
func InitDisk() (d []Disk, err error) {
for i := range global.GVA_CONFIG.DiskList {
mp := global.GVA_CONFIG.DiskList[i].MountPoint
if u, err := disk.Usage(mp); err != nil {
return d, err
} else {
d = append(d, Disk{
MountPoint: mp,
UsedMB: int(u.Used) / MB,
UsedGB: int(u.Used) / GB,
TotalMB: int(u.Total) / MB,
TotalGB: int(u.Total) / GB,
UsedPercent: int(u.UsedPercent),
})
}
}
return d, nil
}