@@ -70,7 +70,7 @@ type IContainerService interface {
7070 ContainerUpgrade (req dto.ContainerUpgrade ) error
7171 ContainerInfo (req dto.OperationWithName ) (* dto.ContainerOperate , error )
7272 ContainerListStats () ([]dto.ContainerListStats , error )
73- ContainerItemStats (containerID string ) (dto.ContainerItemStats , error )
73+ ContainerItemStats (req dto. OperationWithName ) (dto.ContainerItemStats , error )
7474 LoadResourceLimit () (* dto.ResourceLimit , error )
7575 ContainerRename (req dto.ContainerRename ) error
7676 ContainerCommit (req dto.ContainerCommit ) error
@@ -199,34 +199,8 @@ func (u *ContainerService) LoadStatus() (dto.ContainerStatus, error) {
199199 defer client .Close ()
200200 c := context .Background ()
201201
202- usage , err := client .DiskUsage (c , types.DiskUsageOptions {})
203- if err != nil {
204- return data , err
205- }
206-
207- data .ImageCount = len (usage .Images )
208- data .VolumeCount = len (usage .Volumes )
209- for _ , item := range usage .Images {
210- data .ImageUsage += item .Size
211- if item .Containers < 1 {
212- data .ImageReclaimable += item .Size
213- }
214- }
215- for _ , item := range usage .Containers {
216- data .ContainerUsage += item .SizeRw
217- if item .State != "running" {
218- data .ContainerReclaimable += item .SizeRw
219- }
220- }
221- for _ , item := range usage .Volumes {
222- data .VolumeUsage += item .UsageData .Size
223- if item .UsageData .RefCount == 0 {
224- data .VolumeReclaimable += item .UsageData .Size
225- }
226- }
227- for _ , item := range usage .BuildCache {
228- data .BuildCacheUsage += item .Size
229- }
202+ images , _ := client .ImageList (c , image.ListOptions {All : true })
203+ data .ImageCount = len (images )
230204 repo , _ := imageRepoRepo .List ()
231205 data .RepoCount = len (repo )
232206 templates , _ := composeRepo .List ()
@@ -236,8 +210,9 @@ func (u *ContainerService) LoadStatus() (dto.ContainerStatus, error) {
236210 volumes , _ := client .VolumeList (c , volume.ListOptions {})
237211 data .VolumeCount = len (volumes .Volumes )
238212 data .ComposeCount = loadComposeCount (client )
239- data .ContainerCount = len (usage .Containers )
240- for _ , item := range usage .Containers {
213+ containers , _ := client .ContainerList (c , container.ListOptions {All : true })
214+ data .ContainerCount = len (containers )
215+ for _ , item := range containers {
241216 switch item .State {
242217 case "created" :
243218 data .Created ++
@@ -257,19 +232,48 @@ func (u *ContainerService) LoadStatus() (dto.ContainerStatus, error) {
257232 }
258233 return data , nil
259234}
260- func (u * ContainerService ) ContainerItemStats (containerID string ) (dto.ContainerItemStats , error ) {
235+ func (u * ContainerService ) ContainerItemStats (req dto. OperationWithName ) (dto.ContainerItemStats , error ) {
261236 var data dto.ContainerItemStats
262237 client , err := docker .NewDockerClient ()
263238 if err != nil {
264239 return data , err
265240 }
266- defer client .Close ()
267- containerInfo , _ , err := client .ContainerInspectWithRaw (context .Background (), containerID , true )
241+ if req .Name != "system" {
242+ defer client .Close ()
243+ containerInfo , _ , err := client .ContainerInspectWithRaw (context .Background (), req .Name , true )
244+ if err != nil {
245+ return data , err
246+ }
247+ data .SizeRw = * containerInfo .SizeRw
248+ data .SizeRootFs = * containerInfo .SizeRootFs
249+ return data , nil
250+ }
251+
252+ usage , err := client .DiskUsage (context .Background (), types.DiskUsageOptions {})
268253 if err != nil {
269254 return data , err
270255 }
271- data .SizeRw = * containerInfo .SizeRw
272- data .SizeRootFs = * containerInfo .SizeRootFs
256+ for _ , item := range usage .Images {
257+ data .ImageUsage += item .Size
258+ if item .Containers < 1 {
259+ data .ImageReclaimable += item .Size
260+ }
261+ }
262+ for _ , item := range usage .Containers {
263+ data .ContainerUsage += item .SizeRw
264+ if item .State != "running" {
265+ data .ContainerReclaimable += item .SizeRw
266+ }
267+ }
268+ for _ , item := range usage .Volumes {
269+ data .VolumeUsage += item .UsageData .Size
270+ if item .UsageData .RefCount == 0 {
271+ data .VolumeReclaimable += item .UsageData .Size
272+ }
273+ }
274+ for _ , item := range usage .BuildCache {
275+ data .BuildCacheUsage += item .Size
276+ }
273277 return data , nil
274278}
275279func (u * ContainerService ) ContainerListStats () ([]dto.ContainerListStats , error ) {
@@ -1786,9 +1790,9 @@ func searchWithFilter(req dto.PageContainer, containers []container.Summary) []d
17861790 }
17871791 records = append (records , info )
17881792 }
1789- descriptions , _ := settingRepo .GetDescriptionList (repo .WithByType ("container" ))
1793+ dscriptions , _ := settingRepo .GetDescriptionList (repo .WithByType ("container" ))
17901794 for i := 0 ; i < len (records ); i ++ {
1791- for _ , desc := range descriptions {
1795+ for _ , desc := range dscriptions {
17921796 if desc .ID == records [i ].ContainerID {
17931797 records [i ].Description = desc .Description
17941798 records [i ].IsPinned = desc .IsPinned
0 commit comments