fix: 优化了概览页、监控页选项排序

pull/450/head
ssongliu 2023-03-29 21:50:08 +08:00 committed by ssongliu
parent b06058ec18
commit c927132aa6
10 changed files with 118 additions and 174 deletions

View File

@ -1,6 +1,7 @@
package v1
import (
"sort"
"time"
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
@ -88,6 +89,7 @@ func (b *BaseApi) GetNetworkOptions(c *gin.Context) {
for _, net := range netStat {
options = append(options, net.Name)
}
sort.Strings(options)
helper.SuccessWithData(c, options)
}
@ -98,5 +100,6 @@ func (b *BaseApi) GetIOOptions(c *gin.Context) {
for _, net := range diskStat {
options = append(options, net.Name)
}
sort.Strings(options)
helper.SuccessWithData(c, options)
}

View File

@ -3,13 +3,6 @@ package dto
import "time"
type DashboardBase struct {
HaloID uint `json:"haloID"`
DateeaseID uint `json:"dateeaseID"`
JumpServerID uint `json:"jumpserverID"`
MeterSphereID uint `json:"metersphereID"`
KubeoperatorID uint `json:"kubeoperatorID"`
KubepiID uint `json:"kubepiID"`
WebsiteNumber int `json:"websiteNumber"`
DatabaseNumber int `json:"databaseNumber"`
CronjobNumber int `json:"cronjobNumber"`

View File

@ -39,27 +39,6 @@ func (u *DashboardService) LoadBaseInfo(ioOption string, netOption string) (*dto
ss, _ := json.Marshal(hostInfo)
baseInfo.VirtualizationSystem = string(ss)
apps, err := appRepo.GetBy()
if err != nil {
return nil, err
}
for _, app := range apps {
switch app.Key {
case "dateease":
baseInfo.DateeaseID = app.ID
case "halo":
baseInfo.HaloID = app.ID
case "metersphere":
baseInfo.MeterSphereID = app.ID
case "jumpserver":
baseInfo.JumpServerID = app.ID
case "kubeoperator":
baseInfo.KubeoperatorID = app.ID
case "kubepi":
baseInfo.KubepiID = app.ID
}
}
appInstall, err := appInstallRepo.ListBy()
if err != nil {
return nil, err
@ -169,10 +148,10 @@ func loadDiskInfo() []dto.DiskInfo {
return datas
}
var excludes = []string{"/mnt/cdrom", "/boot", "/boot/efi", "/dev", "/dev/shm", "/run/lock", "/run", "/run/shm", "/run/user"}
for _, part := range parts {
for i := 0; i < len(parts); i++ {
isExclude := false
for _, exclude := range excludes {
if part.Mountpoint == exclude {
if parts[i].Mountpoint == exclude {
isExclude = true
break
}
@ -180,11 +159,11 @@ func loadDiskInfo() []dto.DiskInfo {
if isExclude {
continue
}
state, _ := disk.Usage("/")
state, _ := disk.Usage(parts[i].Mountpoint)
var itemData dto.DiskInfo
itemData.Path = part.Mountpoint
itemData.Type = part.Fstype
itemData.Device = part.Device
itemData.Path = parts[i].Mountpoint
itemData.Type = parts[i].Fstype
itemData.Device = parts[i].Device
itemData.Total = state.Total
itemData.Free = state.Free
itemData.Used = state.Used

View File

@ -9171,33 +9171,15 @@ var doc = `{
"databaseNumber": {
"type": "integer"
},
"dateeaseID": {
"type": "integer"
},
"haloID": {
"type": "integer"
},
"hostname": {
"type": "string"
},
"jumpserverID": {
"type": "integer"
},
"kernelArch": {
"type": "string"
},
"kernelVersion": {
"type": "string"
},
"kubeoperatorID": {
"type": "integer"
},
"kubepiID": {
"type": "integer"
},
"metersphereID": {
"type": "integer"
},
"os": {
"type": "string"
},
@ -9239,20 +9221,11 @@ var doc = `{
"cpuUsedPercent": {
"type": "number"
},
"free": {
"type": "integer"
},
"inodesFree": {
"type": "integer"
},
"inodesTotal": {
"type": "integer"
},
"inodesUsed": {
"type": "integer"
},
"inodesUsedPercent": {
"type": "number"
"diskData": {
"type": "array",
"items": {
"$ref": "#/definitions/dto.DiskInfo"
}
},
"ioCount": {
"type": "integer"
@ -9305,11 +9278,40 @@ var doc = `{
"timeSinceUptime": {
"type": "string"
},
"uptime": {
"type": "integer"
}
}
},
"dto.DiskInfo": {
"type": "object",
"properties": {
"device": {
"type": "string"
},
"free": {
"type": "integer"
},
"inodesFree": {
"type": "integer"
},
"inodesTotal": {
"type": "integer"
},
"inodesUsed": {
"type": "integer"
},
"inodesUsedPercent": {
"type": "number"
},
"path": {
"type": "string"
},
"total": {
"type": "integer"
},
"uptime": {
"type": "integer"
"type": {
"type": "string"
},
"used": {
"type": "integer"

View File

@ -9157,33 +9157,15 @@
"databaseNumber": {
"type": "integer"
},
"dateeaseID": {
"type": "integer"
},
"haloID": {
"type": "integer"
},
"hostname": {
"type": "string"
},
"jumpserverID": {
"type": "integer"
},
"kernelArch": {
"type": "string"
},
"kernelVersion": {
"type": "string"
},
"kubeoperatorID": {
"type": "integer"
},
"kubepiID": {
"type": "integer"
},
"metersphereID": {
"type": "integer"
},
"os": {
"type": "string"
},
@ -9225,20 +9207,11 @@
"cpuUsedPercent": {
"type": "number"
},
"free": {
"type": "integer"
},
"inodesFree": {
"type": "integer"
},
"inodesTotal": {
"type": "integer"
},
"inodesUsed": {
"type": "integer"
},
"inodesUsedPercent": {
"type": "number"
"diskData": {
"type": "array",
"items": {
"$ref": "#/definitions/dto.DiskInfo"
}
},
"ioCount": {
"type": "integer"
@ -9291,11 +9264,40 @@
"timeSinceUptime": {
"type": "string"
},
"uptime": {
"type": "integer"
}
}
},
"dto.DiskInfo": {
"type": "object",
"properties": {
"device": {
"type": "string"
},
"free": {
"type": "integer"
},
"inodesFree": {
"type": "integer"
},
"inodesTotal": {
"type": "integer"
},
"inodesUsed": {
"type": "integer"
},
"inodesUsedPercent": {
"type": "number"
},
"path": {
"type": "string"
},
"total": {
"type": "integer"
},
"uptime": {
"type": "integer"
"type": {
"type": "string"
},
"used": {
"type": "integer"

View File

@ -443,24 +443,12 @@ definitions:
$ref: '#/definitions/dto.DashboardCurrent'
databaseNumber:
type: integer
dateeaseID:
type: integer
haloID:
type: integer
hostname:
type: string
jumpserverID:
type: integer
kernelArch:
type: string
kernelVersion:
type: string
kubeoperatorID:
type: integer
kubepiID:
type: integer
metersphereID:
type: integer
os:
type: string
platform:
@ -488,16 +476,10 @@ definitions:
type: number
cpuUsedPercent:
type: number
free:
type: integer
inodesFree:
type: integer
inodesTotal:
type: integer
inodesUsed:
type: integer
inodesUsedPercent:
type: number
diskData:
items:
$ref: '#/definitions/dto.DiskInfo'
type: array
ioCount:
type: integer
ioReadBytes:
@ -532,10 +514,29 @@ definitions:
type: string
timeSinceUptime:
type: string
total:
type: integer
uptime:
type: integer
type: object
dto.DiskInfo:
properties:
device:
type: string
free:
type: integer
inodesFree:
type: integer
inodesTotal:
type: integer
inodesUsed:
type: integer
inodesUsedPercent:
type: number
path:
type: string
total:
type: integer
type:
type: string
used:
type: integer
usedPercent:

View File

@ -1,12 +1,5 @@
export namespace Dashboard {
export interface BaseInfo {
haloID: number;
dateeaseID: number;
jumpserverID: number;
metersphereID: number;
kubeoperatorID: number;
kubepiID: number;
websiteNumber: number;
databaseNumber: number;
cronjobNumber: number;

View File

@ -41,7 +41,6 @@
<script lang="ts" setup>
import { App } from '@/api/interface/app';
import { Dashboard } from '@/api/interface/dashboard';
import { SearchApp } from '@/api/modules/app';
import { reactive, ref } from 'vue';
import { useI18n } from 'vue-i18n';
@ -57,26 +56,10 @@ let req = reactive({
recommend: true,
});
const baseInfo = ref({
haloID: 0,
dateeaseID: 0,
jumpserverID: 0,
metersphereID: 0,
kubeoperatorID: 0,
kubepiID: 0,
});
let loading = ref(false);
let apps = ref<App.App[]>([]);
const acceptParams = (base: Dashboard.BaseInfo): void => {
baseInfo.value.haloID = base.haloID;
baseInfo.value.dateeaseID = base.dateeaseID;
baseInfo.value.jumpserverID = base.jumpserverID;
baseInfo.value.metersphereID = base.metersphereID;
baseInfo.value.kubeoperatorID = base.kubeoperatorID;
baseInfo.value.kubepiID = base.kubepiID;
const acceptParams = (): void => {
search(req);
};

View File

@ -234,13 +234,6 @@ const searchInfo = reactive({
});
const baseInfo = ref<Dashboard.BaseInfo>({
haloID: 0,
dateeaseID: 0,
jumpserverID: 0,
metersphereID: 0,
kubeoperatorID: 0,
kubepiID: 0,
websiteNumber: 0,
databaseNumber: 0,
cronjobNumber: 0,
@ -341,7 +334,7 @@ const onLoadBaseInfo = async (isInit: boolean, range: string) => {
currentInfo.value = baseInfo.value.currentInfo;
onLoadCurrentInfo();
statuRef.value.acceptParams(currentInfo.value, baseInfo.value);
appRef.value.acceptParams(baseInfo.value);
appRef.value.acceptParams();
if (isInit) {
// window.addEventListener('resize', changeChartSize);
timer = setInterval(async () => {

View File

@ -111,18 +111,11 @@
import { Dashboard } from '@/api/interface/dashboard';
import i18n from '@/lang';
import * as echarts from 'echarts';
import { onBeforeUnmount, onMounted, ref } from 'vue';
import { nextTick, onBeforeUnmount, onMounted, ref } from 'vue';
import { GlobalStore } from '@/store';
const globalStore = GlobalStore();
const baseInfo = ref<Dashboard.BaseInfo>({
haloID: 0,
dateeaseID: 0,
jumpserverID: 0,
metersphereID: 0,
kubeoperatorID: 0,
kubepiID: 0,
websiteNumber: 0,
databaseNumber: 0,
cronjobNumber: 0,
@ -181,13 +174,15 @@ const acceptParams = (current: Dashboard.CurrentInfo, base: Dashboard.BaseInfo):
freshChart('cpu', 'CPU', formatNumber(currentInfo.value.cpuUsedPercent));
freshChart('memory', i18n.global.t('monitor.memory'), formatNumber(currentInfo.value.MemoryUsedPercent));
freshChart('load', i18n.global.t('home.load'), formatNumber(currentInfo.value.loadUsagePercent));
for (let i = 0; i < currentInfo.value.diskData.length; i++) {
freshChart(
'disk' + i,
currentInfo.value.diskData[i].path,
formatNumber(currentInfo.value.diskData[i].usedPercent),
);
}
nextTick(() => {
for (let i = 0; i < currentInfo.value.diskData.length; i++) {
freshChart(
'disk' + i,
currentInfo.value.diskData[i].path,
formatNumber(currentInfo.value.diskData[i].usedPercent),
);
}
});
};
const freshChart = (chartName: string, Title: string, Data: number) => {