diff --git a/agent/app/dto/container.go b/agent/app/dto/container.go index 0520e153d..6170c4e42 100644 --- a/agent/app/dto/container.go +++ b/agent/app/dto/container.go @@ -48,6 +48,16 @@ type ContainerStatus struct { Removing uint `json:"removing"` Exited uint `json:"exited"` Dead uint `json:"dead"` + + ContainerCount int `json:"containerCount"` + ComposeCount int `json:"composeCount"` + ComposeTemplateCount int `json:"composeTemplateCount"` + ImageCount int `json:"imageCount"` + NetworkCount int `json:"networkCount"` + VolumeCount int `json:"volumeCount"` + RepoCount int `json:"repoCount"` + + ImageSize uint64 `json:"imageSize"` } type ResourceLimit struct { CPU int `json:"cpu"` diff --git a/agent/app/service/container.go b/agent/app/service/container.go index 242bcf6e6..1d79b7ad4 100644 --- a/agent/app/service/container.go +++ b/agent/app/service/container.go @@ -40,6 +40,7 @@ import ( "github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/registry" + "github.com/docker/docker/api/types/volume" "github.com/docker/docker/client" "github.com/docker/go-connections/nat" "github.com/gorilla/websocket" @@ -248,7 +249,22 @@ func (u *ContainerService) LoadStatus() (dto.ContainerStatus, error) { return data, err } defer client.Close() - containers, err := client.ContainerList(context.Background(), container.ListOptions{All: true}) + c := context.Background() + images, _ := client.ImageList(c, image.ListOptions{}) + for _, image := range images { + data.ImageSize += uint64(image.Size) + } + data.ImageCount = len(images) + repo, _ := imageRepoRepo.List() + data.RepoCount = len(repo) + templates, _ := composeRepo.List() + data.ComposeTemplateCount = len(templates) + networks, _ := client.NetworkList(c, network.ListOptions{}) + data.NetworkCount = len(networks) + volumes, _ := client.VolumeList(c, volume.ListOptions{}) + data.VolumeCount = len(volumes.Volumes) + data.ComposeCount = loadComposeCount(client) + containers, err := client.ContainerList(c, container.ListOptions{All: true}) if err != nil { return data, err } @@ -271,6 +287,7 @@ func (u *ContainerService) LoadStatus() (dto.ContainerStatus, error) { data.Removing++ } } + data.ContainerCount = int(data.All) return data, nil } func (u *ContainerService) ContainerListStats() ([]dto.ContainerListStats, error) { @@ -1363,3 +1380,29 @@ func simplifyPort(ports []types.Port) []string { } return datas } + +func loadComposeCount(client *client.Client) int { + options := container.ListOptions{All: true} + options.Filters = filters.NewArgs() + options.Filters.Add("label", composeProjectLabel) + list, err := client.ContainerList(context.Background(), options) + if err != nil { + return 0 + } + composeCreatedByLocal, _ := composeRepo.ListRecord() + composeMap := make(map[string]struct{}) + for _, container := range list { + if name, ok := container.Labels[composeProjectLabel]; ok { + if _, has := composeMap[name]; !has { + composeMap[name] = struct{}{} + } + } + } + for _, compose := range composeCreatedByLocal { + if _, has := composeMap[compose.Name]; !has { + composeMap[compose.Name] = struct{}{} + } + } + + return len(composeMap) +} diff --git a/frontend/src/api/interface/container.ts b/frontend/src/api/interface/container.ts index b85b39be1..cf7de7ffb 100644 --- a/frontend/src/api/interface/container.ts +++ b/frontend/src/api/interface/container.ts @@ -33,6 +33,16 @@ export namespace Container { removing: number; exited: number; dead: number; + + containerCount: number; + composeCount: number; + composeTemplateCount: number; + imageCount: number; + networkCount: number; + volumeCount: number; + repoCount: number; + + imageSize: number; } export interface ResourceLimit { cpu: number; diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index 1b5cb952d..e84c60a50 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -794,6 +794,7 @@ const message = { composeOperatorHelper: '{1} operation will be performed on {0}. Do you want to continue?', setting: 'Setting', + goSetting: 'Go to edit', operatorStatusHelper: 'This action will {0} Docker service, do you want to continue?', dockerStatus: 'Docker Service', daemonJsonPathHelper: 'Ensure that the configuration path is the same as that specified in docker.service.', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 3e7cdaea6..115985d2f 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -763,6 +763,7 @@ const message = { composeOperatorHelper: '將對 {0} 進行 {1} 操作,是否繼續?', setting: '配置', + goSetting: '去修改', operatorStatusHelper: '此操作將{0}Docker 服務,是否繼續?', dockerStatus: 'Docker 服務', daemonJsonPathHelper: '請保證配置路徑與 docker.service 中指定的配置路徑保持一致。', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 6fe519874..2446103ae 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -764,6 +764,7 @@ const message = { composeOperatorHelper: '将对 {0} 进行 {1} 操作,是否继续?', setting: '配置', + goSetting: '去修改', operatorStatusHelper: '此操作将{0}Docker 服务,是否继续?', dockerStatus: 'Docker 服务', daemonJsonPathHelper: '请保证配置路径与 docker.service 中指定的配置路径保持一致。', diff --git a/frontend/src/routers/modules/container.ts b/frontend/src/routers/modules/container.ts index b10373e09..d95b073e3 100644 --- a/frontend/src/routers/modules/container.ts +++ b/frontend/src/routers/modules/container.ts @@ -13,10 +13,21 @@ const containerRouter = { { path: '/containers', name: 'Containers', - redirect: '/containers/container', + redirect: '/containers/dashboard', component: () => import('@/views/container/index.vue'), meta: {}, children: [ + { + path: 'dashboard', + name: 'ContainerDashboard', + component: () => import('@/views/container/dashboard/index.vue'), + props: true, + hidden: true, + meta: { + activeMenu: '/containers', + requiresAuth: false, + }, + }, { path: 'container', name: 'Container', diff --git a/frontend/src/views/container/dashboard/index.vue b/frontend/src/views/container/dashboard/index.vue new file mode 100644 index 000000000..e1ef74835 --- /dev/null +++ b/frontend/src/views/container/dashboard/index.vue @@ -0,0 +1,190 @@ + + + + + diff --git a/frontend/src/views/container/index.vue b/frontend/src/views/container/index.vue index fae10c860..e84d40272 100644 --- a/frontend/src/views/container/index.vue +++ b/frontend/src/views/container/index.vue @@ -11,6 +11,10 @@ import i18n from '@/lang'; const buttons = [ + { + label: i18n.global.t('home.overview'), + path: '/containers/dashboard', + }, { label: i18n.global.t('container.container'), path: '/containers/container',