mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-06-16 05:55:33 +00:00
Fixed Storage Panel
This commit is contained in:
parent
aad2646cf2
commit
c28e1bbf93
2
UI
2
UI
@ -1 +1 @@
|
|||||||
Subproject commit 216dd1bd47172770ea58353448da992f22237b23
|
Subproject commit 8146d1f4cbaf9135cb4f7d60852cce7fd150bc98
|
@ -27,9 +27,40 @@ type LSBLKModel struct {
|
|||||||
UsedPercent float64 `json:"used_percent"`
|
UsedPercent float64 `json:"used_percent"`
|
||||||
Serial string `json:"serial"`
|
Serial string `json:"serial"`
|
||||||
Children []LSBLKModel `json:"children"`
|
Children []LSBLKModel `json:"children"`
|
||||||
|
SubSystems string `json:"subsystems"`
|
||||||
//详情特有
|
//详情特有
|
||||||
StartSector uint64 `json:"start_sector,omitempty"`
|
StartSector uint64 `json:"start_sector,omitempty"`
|
||||||
Rota bool `json:"rota"` //true(hhd) false(ssd)
|
Rota bool `json:"rota"` //true(hhd) false(ssd)
|
||||||
DiskType string `json:"disk_type"`
|
DiskType string `json:"disk_type"`
|
||||||
EndSector uint64 `json:"end_sector,omitempty"`
|
EndSector uint64 `json:"end_sector,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Drive struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Size uint64 `json:"size"`
|
||||||
|
Model string `json:"model"`
|
||||||
|
Health string `json:"health"`
|
||||||
|
Temperature int `json:"temperature"`
|
||||||
|
DiskType string `json:"disk_type"`
|
||||||
|
NeedFormat bool `json:"need_format"`
|
||||||
|
Serial string `json:"serial"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Storage struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
MountPoint string `json:"mountpoint"`
|
||||||
|
Size string `json:"size"`
|
||||||
|
Avail string `json:"avail"` //可用空间
|
||||||
|
Type string `json:"type"`
|
||||||
|
CreatedAt int64 `json:"create_at"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
DriveName string `json:"drive_name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Summary struct {
|
||||||
|
Size uint64 `json:"size"`
|
||||||
|
Avail uint64 `json:"avail"` //可用空间
|
||||||
|
Health bool `json:"health"`
|
||||||
|
Used uint64 `json:"used"`
|
||||||
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/IceWhaleTech/CasaOS/model"
|
"github.com/IceWhaleTech/CasaOS/model"
|
||||||
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
||||||
@ -27,12 +28,58 @@ var diskMap = make(map[string]string)
|
|||||||
// @Router /disk/list [get]
|
// @Router /disk/list [get]
|
||||||
func GetDiskList(c *gin.Context) {
|
func GetDiskList(c *gin.Context) {
|
||||||
list := service.MyService.Disk().LSBLK()
|
list := service.MyService.Disk().LSBLK()
|
||||||
newList := []model.LSBLKModel{}
|
dbList := service.MyService.Disk().GetSerialAll()
|
||||||
for i := len(list) - 1; i >= 0; i-- {
|
part := make(map[string]int64, len(dbList))
|
||||||
|
for _, v := range dbList {
|
||||||
|
part[v.MountPoint] = v.CreatedAt
|
||||||
|
}
|
||||||
|
findSystem := 0
|
||||||
|
|
||||||
|
disks := []model.Drive{}
|
||||||
|
storage := []model.Storage{}
|
||||||
|
avail := []model.Drive{}
|
||||||
|
|
||||||
|
for i := 0; i < len(list); i++ {
|
||||||
|
disk := model.Drive{}
|
||||||
if list[i].Rota {
|
if list[i].Rota {
|
||||||
list[i].DiskType = "HDD"
|
disk.DiskType = "HDD"
|
||||||
} else {
|
} else {
|
||||||
list[i].DiskType = "SSD"
|
disk.DiskType = "SSD"
|
||||||
|
}
|
||||||
|
disk.Serial = list[i].Serial
|
||||||
|
disk.Name = list[i].Name
|
||||||
|
disk.Size = list[i].Size
|
||||||
|
disk.Path = list[i].Path
|
||||||
|
disk.Model = list[i].Model
|
||||||
|
if len(list[i].Children) > 0 && findSystem == 0 {
|
||||||
|
for j := 0; j < len(list[i].Children); j++ {
|
||||||
|
if list[i].Children[j].MountPoint == "/" {
|
||||||
|
stor := model.Storage{}
|
||||||
|
stor.Name = "System"
|
||||||
|
stor.MountPoint = list[i].Children[j].MountPoint
|
||||||
|
stor.Size = list[i].Children[j].FSSize
|
||||||
|
stor.Avail = list[i].Children[j].FSAvail
|
||||||
|
stor.Path = list[i].Children[j].Path
|
||||||
|
stor.Type = list[i].Children[j].FsType
|
||||||
|
stor.DriveName = "System"
|
||||||
|
disk.Model = "System"
|
||||||
|
if strings.Contains(list[i].Children[i].SubSystems, "mmc") {
|
||||||
|
disk.DiskType = "MMC"
|
||||||
|
} else if strings.Contains(list[i].Children[i].SubSystems, "usb") {
|
||||||
|
disk.DiskType = "USB"
|
||||||
|
}
|
||||||
|
disk.Health = "true"
|
||||||
|
|
||||||
|
disks = append(disks, disk)
|
||||||
|
storage = append(storage, stor)
|
||||||
|
findSystem = 1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if findSystem == 1 {
|
||||||
|
findSystem += 1
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if list[i].Tran == "sata" {
|
if list[i].Tran == "sata" {
|
||||||
temp := service.MyService.Disk().SmartCTL(list[i].Path)
|
temp := service.MyService.Disk().SmartCTL(list[i].Path)
|
||||||
@ -40,29 +87,45 @@ func GetDiskList(c *gin.Context) {
|
|||||||
if reflect.DeepEqual(temp, model.SmartctlA{}) {
|
if reflect.DeepEqual(temp, model.SmartctlA{}) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(list[i].Children) == 1 && len(list[i].Children[0].MountPoint) > 0 {
|
if len(list[i].Children) == 1 && len(list[i].Children[0].MountPoint) > 0 {
|
||||||
|
stor := model.Storage{}
|
||||||
|
stor.MountPoint = list[i].Children[0].MountPoint
|
||||||
|
stor.Size = list[i].Children[0].FSSize
|
||||||
|
stor.Avail = list[i].Children[0].FSAvail
|
||||||
|
stor.Path = list[i].Children[0].Path
|
||||||
|
stor.Type = list[i].Children[0].FsType
|
||||||
|
stor.DriveName = list[i].Name
|
||||||
pathArr := strings.Split(list[i].Children[0].MountPoint, "/")
|
pathArr := strings.Split(list[i].Children[0].MountPoint, "/")
|
||||||
if len(pathArr) == 3 {
|
if len(pathArr) == 3 {
|
||||||
list[i].Children[0].Name = pathArr[2]
|
stor.Name = pathArr[2]
|
||||||
|
}
|
||||||
|
if t, ok := part[list[i].Children[0].MountPoint]; ok {
|
||||||
|
stor.CreatedAt = t
|
||||||
|
}
|
||||||
|
storage = append(storage, stor)
|
||||||
|
} else {
|
||||||
|
if list[i].Children[0].FsType == "ext4" {
|
||||||
|
disk.NeedFormat = false
|
||||||
|
avail = append(avail, disk)
|
||||||
|
} else {
|
||||||
|
disk.NeedFormat = true
|
||||||
|
avail = append(avail, disk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
list[i].Temperature = temp.Temperature.Current
|
disk.Temperature = temp.Temperature.Current
|
||||||
list[i].Health = strconv.FormatBool(temp.SmartStatus.Passed)
|
disk.Health = strconv.FormatBool(temp.SmartStatus.Passed)
|
||||||
|
|
||||||
newList = append(newList, list[i])
|
|
||||||
} else if len(list[i].Children) > 0 && list[i].Children[0].MountPoint == "/" {
|
|
||||||
//system
|
|
||||||
list[i].Children[0].Name = "System"
|
|
||||||
list[i].Model = "System"
|
|
||||||
list[i].DiskType = "EMMC"
|
|
||||||
list[i].Health = "true"
|
|
||||||
newList = append(newList, list[i])
|
|
||||||
|
|
||||||
|
disks = append(disks, disk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
data := make(map[string]interface{}, 3)
|
||||||
|
data["drive"] = disks
|
||||||
|
data["storage"] = storage
|
||||||
|
data["avail"] = avail
|
||||||
|
|
||||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: newList})
|
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: data})
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary get disk list
|
// @Summary get disk list
|
||||||
@ -225,6 +288,7 @@ func AddPartition(c *gin.Context) {
|
|||||||
m.Path = path + "1"
|
m.Path = path + "1"
|
||||||
m.Serial = serial
|
m.Serial = serial
|
||||||
m.State = 0
|
m.State = 0
|
||||||
|
m.CreatedAt = time.Now().Unix()
|
||||||
service.MyService.Disk().SaveMountPoint(m)
|
service.MyService.Disk().SaveMountPoint(m)
|
||||||
|
|
||||||
//mount dir
|
//mount dir
|
||||||
|
@ -263,41 +263,55 @@ func Info(c *gin.Context) {
|
|||||||
|
|
||||||
list := service.MyService.Disk().LSBLK()
|
list := service.MyService.Disk().LSBLK()
|
||||||
|
|
||||||
newList := []model.LSBLKModel{}
|
summary := model.Summary{}
|
||||||
for i := len(list) - 1; i >= 0; i-- {
|
healthy := true
|
||||||
if list[i].Rota {
|
findSystem := 0
|
||||||
list[i].DiskType = "HDD"
|
|
||||||
} else {
|
for i := 0; i < len(list); i++ {
|
||||||
list[i].DiskType = "SSD"
|
if len(list[i].Children) > 0 && findSystem == 0 {
|
||||||
|
for j := 0; j < len(list[i].Children); j++ {
|
||||||
|
if list[i].Children[j].MountPoint == "/" {
|
||||||
|
s, _ := strconv.ParseUint(list[i].Children[j].FSSize, 10, 64)
|
||||||
|
a, _ := strconv.ParseUint(list[i].Children[j].FSAvail, 10, 64)
|
||||||
|
u, _ := strconv.ParseUint(list[i].Children[j].FSUsed, 10, 64)
|
||||||
|
summary.Size += s
|
||||||
|
summary.Avail += a
|
||||||
|
summary.Used += u
|
||||||
|
findSystem = 1
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if findSystem == 1 {
|
||||||
|
findSystem += 1
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if list[i].Tran == "sata" {
|
if list[i].Tran == "sata" {
|
||||||
|
|
||||||
temp := service.MyService.Disk().SmartCTL(list[i].Path)
|
temp := service.MyService.Disk().SmartCTL(list[i].Path)
|
||||||
if reflect.DeepEqual(temp, model.SmartctlA{}) {
|
if reflect.DeepEqual(temp, model.SmartctlA{}) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(list[i].Children) == 1 && len(list[i].Children[0].MountPoint) > 0 {
|
|
||||||
pathArr := strings.Split(list[i].Children[0].MountPoint, "/")
|
|
||||||
if len(pathArr) == 3 {
|
|
||||||
list[i].Children[0].Name = pathArr[2]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
list[i].Temperature = temp.Temperature.Current
|
//list[i].Temperature = temp.Temperature.Current
|
||||||
list[i].Health = strconv.FormatBool(temp.SmartStatus.Passed)
|
if !temp.SmartStatus.Passed {
|
||||||
newList = append(newList, list[i])
|
healthy = false
|
||||||
} else if len(list[i].Children) > 0 && list[i].Children[0].MountPoint == "/" {
|
}
|
||||||
//system
|
if len(list[i].Children) > 0 {
|
||||||
list[i].Children[0].Name = "System"
|
for _, v := range list[i].Children {
|
||||||
list[i].Model = "System"
|
s, _ := strconv.ParseUint(v.FSSize, 10, 64)
|
||||||
list[i].DiskType = "EMMC"
|
a, _ := strconv.ParseUint(v.FSAvail, 10, 64)
|
||||||
list[i].Health = "true"
|
u, _ := strconv.ParseUint(v.FSUsed, 10, 64)
|
||||||
newList = append(newList, list[i])
|
summary.Size += s
|
||||||
|
summary.Avail += a
|
||||||
|
summary.Used += u
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data["disk"] = newList
|
summary.Health = healthy
|
||||||
|
data["disk"] = summary
|
||||||
cpu := service.MyService.ZiMa().GetCpuPercent()
|
cpu := service.MyService.ZiMa().GetCpuPercent()
|
||||||
num := service.MyService.ZiMa().GetCpuCoreNum()
|
num := service.MyService.ZiMa().GetCpuCoreNum()
|
||||||
cpuData := make(map[string]interface{})
|
cpuData := make(map[string]interface{})
|
||||||
|
@ -7,6 +7,7 @@ type SerialDisk struct {
|
|||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
State int `json:"state"`
|
State int `json:"state"`
|
||||||
MountPoint string `json:"mount_point"`
|
MountPoint string `json:"mount_point"`
|
||||||
|
CreatedAt int64 `json:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *SerialDisk) TableName() string {
|
func (p *SerialDisk) TableName() string {
|
||||||
|
BIN
web/img/storage.d487ddb6.png
Normal file
BIN
web/img/storage.d487ddb6.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.6 KiB |
370
web/js/2.js
370
web/js/2.js
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user