mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-01-19 16:29:17 +08:00
fix: 监控数据查询数据为空时,重新渲染
This commit is contained in:
parent
df60a6ccde
commit
ab5841e85b
@ -73,7 +73,6 @@ func (b *BaseApi) WsSsh(c *gin.Context) {
|
|||||||
|
|
||||||
<-quitChan
|
<-quitChan
|
||||||
|
|
||||||
global.LOG.Info("websocket finished")
|
|
||||||
if wshandleError(wsConn, err) {
|
if wshandleError(wsConn, err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,6 @@ type DashboardBase struct {
|
|||||||
KernelArch string `json:"kernelArch"`
|
KernelArch string `json:"kernelArch"`
|
||||||
KernelVersion string `json:"kernelVersion"`
|
KernelVersion string `json:"kernelVersion"`
|
||||||
VirtualizationSystem string `json:"virtualizationSystem"`
|
VirtualizationSystem string `json:"virtualizationSystem"`
|
||||||
Uptime string `json:"uptime"`
|
|
||||||
TimeSinceUptime string `json:"timeSinceUptime"`
|
|
||||||
|
|
||||||
CPUCores int `json:"cpuCores"`
|
CPUCores int `json:"cpuCores"`
|
||||||
CPULogicalCores int `json:"cpuLogicalCores"`
|
CPULogicalCores int `json:"cpuLogicalCores"`
|
||||||
@ -34,6 +32,9 @@ type DashboardBase struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type DashboardCurrent struct {
|
type DashboardCurrent struct {
|
||||||
|
Uptime uint64 `json:"uptime"`
|
||||||
|
TimeSinceUptime string `json:"timeSinceUptime"`
|
||||||
|
|
||||||
Procs uint64 `json:"procs"`
|
Procs uint64 `json:"procs"`
|
||||||
|
|
||||||
Load1 float64 `json:"load1"`
|
Load1 float64 `json:"load1"`
|
||||||
|
@ -2,9 +2,6 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"os/exec"
|
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
||||||
@ -42,18 +39,6 @@ func (u *DashboardService) LoadBaseInfo(ioOption string, netOption string) (*dto
|
|||||||
ss, _ := json.Marshal(hostInfo)
|
ss, _ := json.Marshal(hostInfo)
|
||||||
baseInfo.VirtualizationSystem = string(ss)
|
baseInfo.VirtualizationSystem = string(ss)
|
||||||
|
|
||||||
cmd := exec.Command("uptime", "-s")
|
|
||||||
stdout, err := cmd.CombinedOutput()
|
|
||||||
if err == nil {
|
|
||||||
baseInfo.Uptime = string(stdout)
|
|
||||||
uptime, err := time.Parse("2006-01-02 15:04:05", strings.ReplaceAll(string(stdout), "\n", ""))
|
|
||||||
if err == nil {
|
|
||||||
hours := int(time.Since(uptime).Hours())
|
|
||||||
minutes := int(time.Since(uptime).Minutes())
|
|
||||||
baseInfo.TimeSinceUptime = fmt.Sprintf("%ddays %dhours %dmimutes", hours/24, hours%24, minutes-hours*60)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
apps, err := appRepo.GetBy()
|
apps, err := appRepo.GetBy()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -111,6 +96,8 @@ func (u *DashboardService) LoadBaseInfo(ioOption string, netOption string) (*dto
|
|||||||
func (u *DashboardService) LoadCurrentInfo(ioOption string, netOption string) *dto.DashboardCurrent {
|
func (u *DashboardService) LoadCurrentInfo(ioOption string, netOption string) *dto.DashboardCurrent {
|
||||||
var currentInfo dto.DashboardCurrent
|
var currentInfo dto.DashboardCurrent
|
||||||
hostInfo, _ := host.Info()
|
hostInfo, _ := host.Info()
|
||||||
|
currentInfo.Uptime = hostInfo.Uptime
|
||||||
|
currentInfo.TimeSinceUptime = time.Now().Add(-time.Duration(hostInfo.Uptime) * time.Second).Format("2006-01-02 15:04:05")
|
||||||
currentInfo.Procs = hostInfo.Procs
|
currentInfo.Procs = hostInfo.Procs
|
||||||
|
|
||||||
currentInfo.CPUTotal, _ = cpu.Counts(true)
|
currentInfo.CPUTotal, _ = cpu.Counts(true)
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -165,8 +166,7 @@ func (u *ImageService) ImagePull(req dto.ImagePull) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
imageItemName := strings.ReplaceAll(req.ImageName, ":", "_")
|
imageItemName := strings.ReplaceAll(path.Base(req.ImageName), ":", "_")
|
||||||
imageItemName = strings.ReplaceAll(imageItemName, "/", "@")
|
|
||||||
pathItem := fmt.Sprintf("%s/image_pull_%s_%s.log", dockerLogDir, imageItemName, time.Now().Format("20060102150405"))
|
pathItem := fmt.Sprintf("%s/image_pull_%s_%s.log", dockerLogDir, imageItemName, time.Now().Format("20060102150405"))
|
||||||
file, err := os.OpenFile(pathItem, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
|
file, err := os.OpenFile(pathItem, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -301,8 +301,7 @@ func (u *ImageService) ImagePush(req dto.ImagePush) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
imageItemName := strings.ReplaceAll(req.Name, ":", "_")
|
imageItemName := strings.ReplaceAll(path.Base(req.Name), ":", "_")
|
||||||
imageItemName = strings.ReplaceAll(imageItemName, "/", "@")
|
|
||||||
pathItem := fmt.Sprintf("%s/image_push_%s_%s.log", dockerLogDir, imageItemName, time.Now().Format("20060102150405"))
|
pathItem := fmt.Sprintf("%s/image_push_%s_%s.log", dockerLogDir, imageItemName, time.Now().Format("20060102150405"))
|
||||||
file, err := os.OpenFile(pathItem, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
|
file, err := os.OpenFile(pathItem, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -185,7 +185,6 @@ func (sws *LogicSshWsSession) sendComboOutput(exitCh chan bool) {
|
|||||||
|
|
||||||
func (sws *LogicSshWsSession) Wait(quitChan chan bool) {
|
func (sws *LogicSshWsSession) Wait(quitChan chan bool) {
|
||||||
if err := sws.session.Wait(); err != nil {
|
if err := sws.session.Wait(); err != nil {
|
||||||
global.LOG.Errorf("ssh session wait failed, err: %v", err)
|
|
||||||
setQuit(quitChan)
|
setQuit(quitChan)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,6 @@ export namespace Dashboard {
|
|||||||
kernelArch: string;
|
kernelArch: string;
|
||||||
kernelVersion: string;
|
kernelVersion: string;
|
||||||
virtualizationSystem: string;
|
virtualizationSystem: string;
|
||||||
uptime: string;
|
|
||||||
timeSinceUptime: string;
|
|
||||||
|
|
||||||
cpuCores: number;
|
cpuCores: number;
|
||||||
cpuLogicalCores: number;
|
cpuLogicalCores: number;
|
||||||
@ -30,6 +28,8 @@ export namespace Dashboard {
|
|||||||
currentInfo: CurrentInfo;
|
currentInfo: CurrentInfo;
|
||||||
}
|
}
|
||||||
export interface CurrentInfo {
|
export interface CurrentInfo {
|
||||||
|
uptime: number;
|
||||||
|
timeSinceUptime: string;
|
||||||
procs: number;
|
procs: number;
|
||||||
|
|
||||||
load1: number;
|
load1: number;
|
||||||
|
@ -191,6 +191,7 @@ export default {
|
|||||||
Day: 'Days',
|
Day: 'Days',
|
||||||
Hour: 'Hours',
|
Hour: 'Hours',
|
||||||
Minute: 'Minutes',
|
Minute: 'Minutes',
|
||||||
|
Second: 'Seconds',
|
||||||
|
|
||||||
runSmoothly: 'Run smoothly',
|
runSmoothly: 'Run smoothly',
|
||||||
runNormal: 'Run normal',
|
runNormal: 'Run normal',
|
||||||
@ -596,6 +597,7 @@ export default {
|
|||||||
apps: 'App',
|
apps: 'App',
|
||||||
containers: 'Container',
|
containers: 'Container',
|
||||||
commands: 'Command',
|
commands: 'Command',
|
||||||
|
groups: 'System Group',
|
||||||
backups: 'Backup Account',
|
backups: 'Backup Account',
|
||||||
settings: 'Panel Setting',
|
settings: 'Panel Setting',
|
||||||
cronjobs: 'Cronjob',
|
cronjobs: 'Cronjob',
|
||||||
|
@ -194,8 +194,9 @@ export default {
|
|||||||
uptime: '启动时间',
|
uptime: '启动时间',
|
||||||
runningTime: '运行时间',
|
runningTime: '运行时间',
|
||||||
Day: '天',
|
Day: '天',
|
||||||
Hour: '小时',
|
Hour: '时',
|
||||||
Minute: '分钟',
|
Minute: '分',
|
||||||
|
Second: '秒',
|
||||||
|
|
||||||
runSmoothly: '运行流畅',
|
runSmoothly: '运行流畅',
|
||||||
runNormal: '运行正常',
|
runNormal: '运行正常',
|
||||||
@ -607,6 +608,7 @@ export default {
|
|||||||
hosts: '主机',
|
hosts: '主机',
|
||||||
apps: '应用',
|
apps: '应用',
|
||||||
containers: '容器',
|
containers: '容器',
|
||||||
|
groups: '系统组',
|
||||||
commands: '快捷命令',
|
commands: '快捷命令',
|
||||||
backups: '备份账号',
|
backups: '备份账号',
|
||||||
settings: '面板设置',
|
settings: '面板设置',
|
||||||
|
@ -100,8 +100,10 @@
|
|||||||
{{ baseInfo.kernelVersion }}
|
{{ baseInfo.kernelVersion }}
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item :label="$t('home.kernelArch')">{{ baseInfo.kernelArch }}</el-form-item>
|
<el-form-item :label="$t('home.kernelArch')">{{ baseInfo.kernelArch }}</el-form-item>
|
||||||
<el-form-item :label="$t('home.uptime')">{{ baseInfo.uptime }}</el-form-item>
|
<el-form-item :label="$t('home.uptime')">{{ currentInfo.timeSinceUptime }}</el-form-item>
|
||||||
<el-form-item :label="$t('home.runningTime')">{{ baseInfo.timeSinceUptime }}</el-form-item>
|
<el-form-item :label="$t('home.runningTime')">
|
||||||
|
{{ loadUpTime(currentInfo.uptime) }}
|
||||||
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</el-card>
|
</el-card>
|
||||||
</el-col>
|
</el-col>
|
||||||
@ -227,8 +229,6 @@ const baseInfo = ref<Dashboard.BaseInfo>({
|
|||||||
kernelArch: '',
|
kernelArch: '',
|
||||||
kernelVersion: '',
|
kernelVersion: '',
|
||||||
virtualizationSystem: '',
|
virtualizationSystem: '',
|
||||||
uptime: '',
|
|
||||||
timeSinceUptime: '',
|
|
||||||
|
|
||||||
cpuCores: 0,
|
cpuCores: 0,
|
||||||
cpuLogicalCores: 0,
|
cpuLogicalCores: 0,
|
||||||
@ -236,6 +236,8 @@ const baseInfo = ref<Dashboard.BaseInfo>({
|
|||||||
currentInfo: null,
|
currentInfo: null,
|
||||||
});
|
});
|
||||||
const currentInfo = ref<Dashboard.CurrentInfo>({
|
const currentInfo = ref<Dashboard.CurrentInfo>({
|
||||||
|
uptime: 0,
|
||||||
|
timeSinceUptime: '',
|
||||||
procs: 0,
|
procs: 0,
|
||||||
|
|
||||||
load1: 0,
|
load1: 0,
|
||||||
@ -316,11 +318,6 @@ const onLoadBaseInfo = async (isInit: boolean, range: string) => {
|
|||||||
const res = await loadBaseInfo(searchInfo.ioOption, searchInfo.netOption);
|
const res = await loadBaseInfo(searchInfo.ioOption, searchInfo.netOption);
|
||||||
baseInfo.value = res.data;
|
baseInfo.value = res.data;
|
||||||
currentInfo.value = baseInfo.value.currentInfo;
|
currentInfo.value = baseInfo.value.currentInfo;
|
||||||
if (baseInfo.value.timeSinceUptime) {
|
|
||||||
baseInfo.value.timeSinceUptime.replaceAll('days', i18n.global.t('home.Day'));
|
|
||||||
baseInfo.value.timeSinceUptime.replaceAll('hours', i18n.global.t('home.Hour'));
|
|
||||||
baseInfo.value.timeSinceUptime.replaceAll('minutes', i18n.global.t('home.Minute'));
|
|
||||||
}
|
|
||||||
onLoadCurrentInfo();
|
onLoadCurrentInfo();
|
||||||
statuRef.value.acceptParams(currentInfo.value, baseInfo.value);
|
statuRef.value.acceptParams(currentInfo.value, baseInfo.value);
|
||||||
appRef.value.acceptParams(baseInfo.value);
|
appRef.value.acceptParams(baseInfo.value);
|
||||||
@ -334,6 +331,8 @@ const onLoadBaseInfo = async (isInit: boolean, range: string) => {
|
|||||||
|
|
||||||
const onLoadCurrentInfo = async () => {
|
const onLoadCurrentInfo = async () => {
|
||||||
const res = await loadCurrentInfo(searchInfo.ioOption, searchInfo.netOption);
|
const res = await loadCurrentInfo(searchInfo.ioOption, searchInfo.netOption);
|
||||||
|
currentInfo.value.timeSinceUptime = res.data.timeSinceUptime;
|
||||||
|
|
||||||
currentChartInfo.netBytesSent = Number(
|
currentChartInfo.netBytesSent = Number(
|
||||||
((res.data.netBytesSent - currentInfo.value.netBytesSent) / 1024 / 3).toFixed(2),
|
((res.data.netBytesSent - currentInfo.value.netBytesSent) / 1024 / 3).toFixed(2),
|
||||||
);
|
);
|
||||||
@ -378,6 +377,47 @@ const onLoadCurrentInfo = async () => {
|
|||||||
statuRef.value.acceptParams(currentInfo.value, baseInfo.value);
|
statuRef.value.acceptParams(currentInfo.value, baseInfo.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function loadUpTime(uptime: number) {
|
||||||
|
if (uptime <= 0) {
|
||||||
|
return '-';
|
||||||
|
}
|
||||||
|
let days = Math.floor(uptime / 86400);
|
||||||
|
let hours = Math.floor((uptime % 86400) / 3600);
|
||||||
|
let minutes = Math.floor((uptime % 3600) / 60);
|
||||||
|
let seconds = uptime % 60;
|
||||||
|
if (days !== 0) {
|
||||||
|
return (
|
||||||
|
days +
|
||||||
|
i18n.global.t('home.Day') +
|
||||||
|
' ' +
|
||||||
|
hours +
|
||||||
|
i18n.global.t('home.Hour') +
|
||||||
|
' ' +
|
||||||
|
minutes +
|
||||||
|
i18n.global.t('home.Minute') +
|
||||||
|
' ' +
|
||||||
|
seconds +
|
||||||
|
i18n.global.t('home.Second')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (hours !== 0) {
|
||||||
|
return (
|
||||||
|
hours +
|
||||||
|
i18n.global.t('home.Hour') +
|
||||||
|
' ' +
|
||||||
|
minutes +
|
||||||
|
i18n.global.t('home.Minute') +
|
||||||
|
' ' +
|
||||||
|
seconds +
|
||||||
|
i18n.global.t('home.Second')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (minutes !== 0) {
|
||||||
|
return minutes + i18n.global.t('home.Minute') + ' ' + seconds + i18n.global.t('home.Second');
|
||||||
|
}
|
||||||
|
return seconds + i18n.global.t('home.Second');
|
||||||
|
}
|
||||||
|
|
||||||
const loadData = async () => {
|
const loadData = async () => {
|
||||||
if (chartOption.value === 'io') {
|
if (chartOption.value === 'io') {
|
||||||
let ioReadYDatas = {
|
let ioReadYDatas = {
|
||||||
|
@ -138,8 +138,6 @@ const baseInfo = ref<Dashboard.BaseInfo>({
|
|||||||
databaseNumber: 0,
|
databaseNumber: 0,
|
||||||
cronjobNumber: 0,
|
cronjobNumber: 0,
|
||||||
appInstalldNumber: 0,
|
appInstalldNumber: 0,
|
||||||
uptime: '',
|
|
||||||
timeSinceUptime: '',
|
|
||||||
|
|
||||||
hostname: '',
|
hostname: '',
|
||||||
os: '',
|
os: '',
|
||||||
@ -156,6 +154,8 @@ const baseInfo = ref<Dashboard.BaseInfo>({
|
|||||||
currentInfo: null,
|
currentInfo: null,
|
||||||
});
|
});
|
||||||
const currentInfo = ref<Dashboard.CurrentInfo>({
|
const currentInfo = ref<Dashboard.CurrentInfo>({
|
||||||
|
uptime: 0,
|
||||||
|
timeSinceUptime: '',
|
||||||
procs: 0,
|
procs: 0,
|
||||||
|
|
||||||
load1: 0,
|
load1: 0,
|
||||||
|
@ -202,11 +202,12 @@ const search = async (param: string) => {
|
|||||||
searchInfo.endTime = searchTime.value[1];
|
searchInfo.endTime = searchTime.value[1];
|
||||||
}
|
}
|
||||||
const res = await loadMonitor(searchInfo);
|
const res = await loadMonitor(searchInfo);
|
||||||
if (res.data[0].value === null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
monitorBase.value = res.data;
|
monitorBase.value = res.data;
|
||||||
for (const item of monitorBase.value) {
|
for (const item of monitorBase.value) {
|
||||||
|
if (!item.value) {
|
||||||
|
item.value = [];
|
||||||
|
item.date = [];
|
||||||
|
}
|
||||||
switch (item.param) {
|
switch (item.param) {
|
||||||
case 'base':
|
case 'base':
|
||||||
let baseDate = item.date.map(function (item: any) {
|
let baseDate = item.date.map(function (item: any) {
|
||||||
|
@ -64,7 +64,7 @@ const panelFormRef = ref<FormInstance>();
|
|||||||
const search = async () => {
|
const search = async () => {
|
||||||
const res = await getSettingInfo();
|
const res = await getSettingInfo();
|
||||||
form.monitorStatus = res.data.monitorStatus;
|
form.monitorStatus = res.data.monitorStatus;
|
||||||
form.monitorStoreDays = res.data.monitorStoreDays;
|
form.monitorStoreDays = Number(res.data.monitorStoreDays);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSave = async (formEl: FormInstance | undefined, key: string, val: any) => {
|
const onSave = async (formEl: FormInstance | undefined, key: string, val: any) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user