Skip to content

Modern Docker Management, Designed for Everyone

fix: show correct stats for remote environments on dashboard (#549)

Kyle Mendell17ab5d03b1ca
diff --git a/backend/internal/api/environment_handler.go b/backend/internal/api/environment_handler.go
index bb1f818b7..05df5bbcf 100644
--- a/backend/internal/api/environment_handler.go
+++ b/backend/internal/api/environment_handler.go
@@ -33,6 +33,8 @@ type EnvironmentHandler struct {
settingsService *services.SettingsService
imageUpdateService *services.ImageUpdateService
updaterService *services.UpdaterService
+ systemService *services.SystemService
+ dockerService *services.DockerClientService
cfg *config.Config
}
@@ -47,6 +49,8 @@ func NewEnvironmentHandler(
volumeService *services.VolumeService,
projectService *services.ProjectService,
settingsService *services.SettingsService,
+ systemService *services.SystemService,
+ dockerService *services.DockerClientService,
authMiddleware *middleware.AuthMiddleware,
cfg *config.Config,
) {
@@ -61,6 +65,8 @@ func NewEnvironmentHandler(
volumeService: volumeService,
projectService: projectService,
settingsService: settingsService,
+ systemService: systemService,
+ dockerService: dockerService,
cfg: cfg,
}
@@ -138,6 +144,7 @@ func NewEnvironmentHandler(
apiGroup.POST("/:id/agent/pair", handler.PairAgent)
apiGroup.GET("/:id/stats/ws", handler.GetStatsWS)
+ apiGroup.GET("/:id/docker/info", handler.GetDockerInfo)
}
}
@@ -203,6 +210,9 @@ func (h *EnvironmentHandler) handleLocalRequest(c *gin.Context, endpoint string)
if h.handleUpdaterEndpoints(c, endpoint) {
return
}
+ if h.handleSystemRoutes(c, endpoint) {
+ return
+ }
c.JSON(http.StatusNotFound, gin.H{
"success": false,
@@ -228,6 +238,22 @@ func (h *EnvironmentHandler) handleUpdaterEndpoints(c *gin.Context, endpoint str
return false
}
+func (h *EnvironmentHandler) handleSystemRoutes(c *gin.Context, endpoint string) bool {
+ systemHandler := &SystemHandler{
+ systemService: h.systemService,
+ dockerService: h.dockerService,
+ }
+ if endpoint == "/docker/info" && c.Request.Method == http.MethodGet {
+ systemHandler.GetDockerInfo(c)
+ return true
+ }
+ return false
+}
+
+func (h *EnvironmentHandler) GetDockerInfo(c *gin.Context) {
+ h.routeRequest(c, "/docker/info")
+}
+
func (h *EnvironmentHandler) UpdaterRun(c *gin.Context) {
h.routeRequest(c, "/updater/run")
}
diff --git a/backend/internal/bootstrap/router_bootstrap.go b/backend/internal/bootstrap/router_bootstrap.go
index 6da028047..be394dd16 100644
--- a/backend/internal/bootstrap/router_bootstrap.go
+++ b/backend/internal/bootstrap/router_bootstrap.go
@@ -65,7 +65,7 @@ func setupRouter(cfg *config.Config, appServices *Services) *gin.Engine {
if cfg.AgentMode {
api.NewHealthHandler(apiGroup)
- api.NewEnvironmentHandler(apiGroup, appServices.Environment, appServices.Container, appServices.Image, appServices.ImageUpdate, appServices.Updater, appServices.Network, appServices.Volume, appServices.Project, appServices.Settings, authMiddleware, cfg)
+ api.NewEnvironmentHandler(apiGroup, appServices.Environment, appServices.Container, appServices.Image, appServices.ImageUpdate, appServices.Updater, appServices.Network, appServices.Volume, appServices.Project, appServices.Settings, appServices.System, appServices.Docker, authMiddleware, cfg)
api.NewSystemHandler(apiGroup, appServices.Docker, appServices.System, authMiddleware)
return router
}
@@ -76,7 +76,7 @@ func setupRouter(cfg *config.Config, appServices *Services) *gin.Engine {
api.NewContainerHandler(apiGroup, appServices.Docker, appServices.Container, appServices.Image, authMiddleware)
api.NewContainerRegistryHandler(apiGroup, appServices.ContainerRegistry, authMiddleware)
api.NewConverterHandler(apiGroup, appServices.Converter, authMiddleware)
- api.NewEnvironmentHandler(apiGroup, appServices.Environment, appServices.Container, appServices.Image, appServices.ImageUpdate, appServices.Updater, appServices.Network, appServices.Volume, appServices.Project, appServices.Settings, authMiddleware, cfg)
+ api.NewEnvironmentHandler(apiGroup, appServices.Environment, appServices.Container, appServices.Image, appServices.ImageUpdate, appServices.Updater, appServices.Network, appServices.Volume, appServices.Project, appServices.Settings, appServices.System, appServices.Docker, authMiddleware, cfg)
api.NewEventHandler(apiGroup, appServices.Event, authMiddleware)
api.NewImageHandler(apiGroup, appServices.Docker, appServices.Image, appServices.ImageUpdate, authMiddleware)
api.NewImageUpdateHandler(apiGroup, appServices.ImageUpdate, authMiddleware)
diff --git a/frontend/src/lib/services/api/environment-api-service.ts b/frontend/src/lib/services/api/environment-api-service.ts
index be5de323d..b807b4c78 100644
--- a/frontend/src/lib/services/api/environment-api-service.ts
+++ b/frontend/src/lib/services/api/environment-api-service.ts
@@ -9,6 +9,7 @@ import type { ImageSummaryDto, ImageUpdateInfoDto, ImageUsageCounts } from '$lib
import type { NetworkSummaryDto, NetworkUsageCounts } from '$lib/types/network.type';
import type { VolumeSummaryDto, VolumeDetailDto, VolumeUsageDto, VolumeUsageCounts } from '$lib/types/volume.type';
import type { AutoUpdateCheck, AutoUpdateResult } from '$lib/types/auto-update.type';
+import type { DockerInfo } from '$lib/types/docker-info.type';
export class EnvironmentAPIService extends BaseAPIService {
private async getCurrentEnvironmentId(): Promise<string> {
@@ -21,6 +22,13 @@ export class EnvironmentAPIService extends BaseAPIService {
return currentEnvironment.id;
}
+ // System Api Calls
+
+ async getDockerInfo(): Promise<DockerInfo> {
+ const envId = await this.getCurrentEnvironmentId();
+ return this.handleResponse(this.api.get(`/environments/${envId}/docker/info`));
+ }
+
// Container Api Calls
async getContainers(options?: SearchPaginationSortRequest): Promise<Paginated<ContainerSummaryDto>> {
diff --git a/frontend/src/routes/dashboard/+page.svelte b/frontend/src/routes/dashboard/+page.svelte
index 36d1685e7..72d96fa09 100644
--- a/frontend/src/routes/dashboard/+page.svelte
+++ b/frontend/src/routes/dashboard/+page.svelte
@@ -116,7 +116,7 @@
isLoading.loadingImages = true;
const [dockerInfoResult, settingsResult, imagesResult, statusCountsResult] = await Promise.allSettled([
- tryCatch(systemAPI.getDockerInfo()),
+ tryCatch(environmentAPI.getDockerInfo()),
tryCatch(settingsAPI.getSettings()),
tryCatch(environmentAPI.getImages(imageRequestOptions)),
tryCatch(environmentAPI.getContainerStatusCounts())
diff --git a/frontend/src/routes/dashboard/+page.ts b/frontend/src/routes/dashboard/+page.ts
index d8a1fd1bd..6304efe5f 100644
--- a/frontend/src/routes/dashboard/+page.ts
+++ b/frontend/src/routes/dashboard/+page.ts
@@ -1,4 +1,4 @@
-import { systemAPI, settingsAPI, environmentAPI } from '$lib/services/api';
+import { settingsAPI, environmentAPI } from '$lib/services/api';
import type { SearchPaginationSortRequest } from '$lib/types/pagination.type';
import type { PageLoad } from './$types';
@@ -28,7 +28,10 @@ export const load: PageLoad = async () => {
const images = await environmentAPI.getImages(imageRequestOptions);
const containerStatusCounts = await environmentAPI.getContainerStatusCounts();
- const [dockerInfoResult, settingsResult] = await Promise.allSettled([systemAPI.getDockerInfo(), settingsAPI.getSettings()]);
+ const [dockerInfoResult, settingsResult] = await Promise.allSettled([
+ environmentAPI.getDockerInfo(),
+ settingsAPI.getSettings()
+ ]);
const dockerInfo = dockerInfoResult.status === 'fulfilled' ? dockerInfoResult.value : null;
const settings = settingsResult.status === 'fulfilled' ? settingsResult.value : null;