From d18cf5f24677d842b5470497a07fd7911334b0f6 Mon Sep 17 00:00:00 2001 From: HynoR <20227709+HynoR@users.noreply.github.com> Date: Wed, 26 Nov 2025 16:40:55 +0800 Subject: [PATCH 1/2] feat: async load data of top CPU and memory processes data --- agent/app/api/v2/dashboard.go | 22 +++++ agent/app/service/dashboard.go | 13 ++- agent/router/ro_dashboard.go | 2 + frontend/src/api/interface/dashboard.ts | 4 +- frontend/src/api/modules/dashboard.ts | 8 ++ frontend/src/views/home/index.vue | 12 ++- frontend/src/views/home/status/index.vue | 102 ++++++++++++++++++++++- 7 files changed, 152 insertions(+), 11 deletions(-) diff --git a/agent/app/api/v2/dashboard.go b/agent/app/api/v2/dashboard.go index 3271b9095596..64cde1294243 100644 --- a/agent/app/api/v2/dashboard.go +++ b/agent/app/api/v2/dashboard.go @@ -179,6 +179,28 @@ func (b *BaseApi) LoadDashboardCurrentInfo(c *gin.Context) { helper.SuccessWithData(c, data) } +// @Tags Dashboard +// @Summary Load top cpu processes +// @Success 200 {Array} dto.Process +// @Security ApiKeyAuth +// @Security Timestamp +// @Router /dashboard/current/top/cpu [get] +func (b *BaseApi) LoadDashboardTopCPU(c *gin.Context) { + data := dashboardService.LoadTopCPU() + helper.SuccessWithData(c, data) +} + +// @Tags Dashboard +// @Summary Load top memory processes +// @Success 200 {Array} dto.Process +// @Security ApiKeyAuth +// @Security Timestamp +// @Router /dashboard/current/top/mem [get] +func (b *BaseApi) LoadDashboardTopMem(c *gin.Context) { + data := dashboardService.LoadTopMem() + helper.SuccessWithData(c, data) +} + // @Tags Dashboard // @Summary System restart // @Accept json diff --git a/agent/app/service/dashboard.go b/agent/app/service/dashboard.go index 4fd3687ab7ca..2e28d00de8ed 100644 --- a/agent/app/service/dashboard.go +++ b/agent/app/service/dashboard.go @@ -39,6 +39,8 @@ type IDashboardService interface { LoadBaseInfo(ioOption string, netOption string) (*dto.DashboardBase, error) LoadCurrentInfoForNode() *dto.NodeCurrent LoadCurrentInfo(ioOption string, netOption string) *dto.DashboardCurrent + LoadTopCPU() []dto.Process + LoadTopMem() []dto.Process LoadQuickOptions() []dto.QuickJump ChangeQuick(req dto.ChangeQuicks) error @@ -217,9 +219,6 @@ func (u *DashboardService) LoadCurrentInfo(ioOption string, netOption string) *d currentInfo.GPUData = loadGPUInfo() currentInfo.XPUData = loadXpuInfo() - currentInfo.TopCPUItems = loadTopCPU() - currentInfo.TopMemItems = loadTopMem() - if ioOption == "all" { diskInfo, _ := disk.IOCounters() for _, state := range diskInfo { @@ -261,6 +260,14 @@ func (u *DashboardService) LoadCurrentInfo(ioOption string, netOption string) *d return ¤tInfo } +func (u *DashboardService) LoadTopCPU() []dto.Process { + return loadTopCPU() +} + +func (u *DashboardService) LoadTopMem() []dto.Process { + return loadTopMem() +} + func (u *DashboardService) LoadAppLauncher(ctx *gin.Context) ([]dto.AppLauncher, error) { var data []dto.AppLauncher appInstalls, err := appInstallRepo.ListBy(context.Background()) diff --git a/agent/router/ro_dashboard.go b/agent/router/ro_dashboard.go index ea167a9a243b..959bd53d1884 100644 --- a/agent/router/ro_dashboard.go +++ b/agent/router/ro_dashboard.go @@ -20,6 +20,8 @@ func (s *DashboardRouter) InitRouter(Router *gin.RouterGroup) { cmdRouter.GET("/base/:ioOption/:netOption", baseApi.LoadDashboardBaseInfo) cmdRouter.GET("/current/node", baseApi.LoadCurrentInfoForNode) cmdRouter.GET("/current/:ioOption/:netOption", baseApi.LoadDashboardCurrentInfo) + cmdRouter.GET("/current/top/cpu", baseApi.LoadDashboardTopCPU) + cmdRouter.GET("/current/top/mem", baseApi.LoadDashboardTopMem) cmdRouter.POST("/system/restart/:operation", baseApi.SystemRestart) } } diff --git a/frontend/src/api/interface/dashboard.ts b/frontend/src/api/interface/dashboard.ts index a87e36b18905..ee5c1a9f3977 100644 --- a/frontend/src/api/interface/dashboard.ts +++ b/frontend/src/api/interface/dashboard.ts @@ -103,8 +103,8 @@ export namespace Dashboard { gpuData: Array; xpuData: Array; - topCPUItems: Array; - topMemItems: Array; + topCPUItems?: Array; + topMemItems?: Array; netBytesSent: number; netBytesRecv: number; diff --git a/frontend/src/api/modules/dashboard.ts b/frontend/src/api/modules/dashboard.ts index 1f1becda5edd..077140db55c1 100644 --- a/frontend/src/api/modules/dashboard.ts +++ b/frontend/src/api/modules/dashboard.ts @@ -29,6 +29,14 @@ export const loadCurrentInfo = (ioOption: string, netOption: string) => { return http.get(`/dashboard/current/${ioOption}/${netOption}`); }; +export const loadTopCPU = () => { + return http.get>(`/dashboard/current/top/cpu`); +}; + +export const loadTopMem = () => { + return http.get>(`/dashboard/current/top/mem`); +}; + export const systemRestart = (operation: string) => { return http.post(`/dashboard/system/restart/${operation}`); }; diff --git a/frontend/src/views/home/index.vue b/frontend/src/views/home/index.vue index fdf93cfd8925..71714f1dc422 100644 --- a/frontend/src/views/home/index.vue +++ b/frontend/src/views/home/index.vue @@ -450,6 +450,14 @@ const currentChartInfo = reactive({ const chartsOption = ref({ ioChart1: null, networkChart: null }); +const updateCurrentInfo = (data: Dashboard.CurrentInfo) => { + currentInfo.value = { + ...data, + topCPUItems: currentInfo.value.topCPUItems || [], + topMemItems: currentInfo.value.topMemItems || [], + }; +}; + const changeOption = async () => { isInit.value = true; loadData(); @@ -484,7 +492,7 @@ const onLoadBaseInfo = async (isInit: boolean, range: string) => { } const res = await loadBaseInfo(searchInfo.ioOption, searchInfo.netOption); baseInfo.value = res.data; - currentInfo.value = baseInfo.value.currentInfo; + updateCurrentInfo(baseInfo.value.currentInfo); onLoadCurrentInfo(); isStatusInit.value = false; statusRef.value?.acceptParams(currentInfo.value, baseInfo.value); @@ -584,7 +592,7 @@ const onLoadCurrentInfo = async () => { timeNetDatas.value.splice(0, 1); } loadData(); - currentInfo.value = res.data; + updateCurrentInfo(res.data); statusRef.value?.acceptParams(currentInfo.value, baseInfo.value); }; diff --git a/frontend/src/views/home/status/index.vue b/frontend/src/views/home/status/index.vue index 90750b35f4ac..1d6d678f5b89 100644 --- a/frontend/src/views/home/status/index.vue +++ b/frontend/src/views/home/status/index.vue @@ -1,7 +1,14 @@