1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-19 16:29:17 +08:00

fix: 概览页磁盘信息获取增加超时时间 (#3074)

Refs #2825
This commit is contained in:
ssongliu 2023-11-27 17:42:08 +08:00 committed by GitHub
parent 50b4458926
commit 807a5071a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 19 deletions

View File

@ -1,9 +1,11 @@
package service
import (
"context"
"encoding/json"
"fmt"
"strings"
"sync"
"time"
"github.com/1Panel-dev/1Panel/backend/app/dto"
@ -179,7 +181,7 @@ type diskInfo struct {
func loadDiskInfo() []dto.DiskInfo {
var datas []dto.DiskInfo
stdout, err := cmd.Exec("df -hT -P|grep '/'|grep -v tmpfs|grep -v 'snap/core'|grep -v udev")
stdout, err := cmd.ExecWithTimeOut("df -hT -P|grep '/'|grep -v tmpfs|grep -v 'snap/core'|grep -v udev", 2*time.Second)
if err != nil {
return datas
}
@ -213,15 +215,26 @@ func loadDiskInfo() []dto.DiskInfo {
mounts = append(mounts, diskInfo{Type: fields[1], Device: fields[0], Mount: fields[6]})
}
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
var wg sync.WaitGroup
wg.Add(len(mounts))
for i := 0; i < len(mounts); i++ {
state, err := disk.Usage(mounts[i].Mount)
go func(index int) {
defer wg.Done()
select {
case <-ctx.Done():
global.LOG.Errorf("load disk info from %s failed, err: timeout", mounts[index].Mount)
return
default:
state, err := disk.Usage(mounts[index].Mount)
if err != nil {
continue
return
}
var itemData dto.DiskInfo
itemData.Path = mounts[i].Mount
itemData.Type = mounts[i].Type
itemData.Device = mounts[i].Device
itemData.Path = mounts[index].Mount
itemData.Type = mounts[index].Type
itemData.Device = mounts[index].Device
itemData.Total = state.Total
itemData.Free = state.Free
itemData.Used = state.Used
@ -232,5 +245,8 @@ func loadDiskInfo() []dto.DiskInfo {
itemData.InodesUsedPercent = state.InodesUsedPercent
datas = append(datas, itemData)
}
}(i)
}
wg.Wait()
return datas
}

View File

@ -393,7 +393,7 @@ const onLoadBaseInfo = async (isInit: boolean, range: string) => {
if (isActive.value && !globalStore.isOnRestart) {
await onLoadCurrentInfo();
}
}, 300000);
}, 3000);
}
};