Skip to content

Commit bb246a1

Browse files
committed
show images, containers count size
1 parent d335155 commit bb246a1

File tree

2 files changed

+54
-31
lines changed

2 files changed

+54
-31
lines changed

docker/docker.go

+51-30
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,23 @@ type MyNetwork struct {
3838
}
3939

4040
type MyContainer struct {
41-
ID string
42-
IDShort string
43-
Name string
44-
NameShort string
45-
Image string
46-
ImageShort string
47-
State string
48-
Status string
49-
Ports []types.Port
50-
Size string
51-
Command string
52-
Env []string
53-
ReadOnly bool
54-
MountedAt string
55-
Network MyNetwork
56-
Mounts []types.MountPoint
41+
ID string
42+
IDShort string
43+
Name string
44+
NameShort string
45+
Image string
46+
ImageShort string
47+
State string
48+
Status string
49+
Ports []types.Port
50+
Size string
51+
SizeOriginal int64
52+
Command string
53+
Env []string
54+
ReadOnly bool
55+
MountedAt string
56+
Network MyNetwork
57+
Mounts []types.MountPoint
5758
}
5859

5960
type MyContainerStats struct {
@@ -172,20 +173,21 @@ func (d *Docker) ContainerList() ([]MyContainer, error) {
172173
}
173174

174175
mc = append(mc, MyContainer{
175-
ID: c.ID,
176-
IDShort: utils.TrimValue(c.ID, 10),
177-
Name: name,
178-
NameShort: utils.TrimValue(name, 20),
179-
Image: c.Image,
180-
ImageShort: utils.TrimValue(c.Image, 20),
181-
State: c.State,
182-
Status: c.Status,
183-
Ports: c.Ports,
184-
Size: utils.FormatSize(*cJSON.SizeRootFs),
185-
Env: cJSON.Config.Env,
186-
Command: strings.Join(cJSON.Config.Entrypoint, " ") + " " + strings.Join(cJSON.Config.Cmd, " "),
187-
ReadOnly: readOnly,
188-
MountedAt: mountedAt,
176+
ID: c.ID,
177+
IDShort: utils.TrimValue(c.ID, 10),
178+
Name: name,
179+
NameShort: utils.TrimValue(name, 20),
180+
Image: c.Image,
181+
ImageShort: utils.TrimValue(c.Image, 20),
182+
State: c.State,
183+
Status: c.Status,
184+
Ports: c.Ports,
185+
Size: utils.FormatSize(*cJSON.SizeRootFs),
186+
SizeOriginal: *cJSON.SizeRootFs,
187+
Env: cJSON.Config.Env,
188+
Command: strings.Join(cJSON.Config.Entrypoint, " ") + " " + strings.Join(cJSON.Config.Cmd, " "),
189+
ReadOnly: readOnly,
190+
MountedAt: mountedAt,
189191
Network: MyNetwork{
190192
Name: networkMode,
191193
IPAddress: ipAddress,
@@ -569,3 +571,22 @@ func (d *Docker) Events() {
569571
}
570572
}()
571573
}
574+
575+
func (d *Docker) GetAllImagesSize() string {
576+
var size int64
577+
for _, image := range d.Images {
578+
size += image.Summary.Size
579+
}
580+
581+
return utils.FormatSize(size)
582+
}
583+
584+
func (d *Docker) GetAllContainersSize() string {
585+
var size int64
586+
587+
for _, container := range d.Containers {
588+
size += container.SizeOriginal
589+
}
590+
591+
return utils.FormatSize(size)
592+
}

models/model.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,12 @@ func (m *model) setContainerList() {
348348
}
349349

350350
func (m *model) getDockerStats() string {
351-
return fmt.Sprintf("\U0001F433 DockerVersion: %s | Containers: %d | Images: %d | Volumes: %d \U0001F5A5 CPU: %d | Memory: %s ",
351+
return fmt.Sprintf("\U0001F433 DockerVersion: %s | Containers: %d (%s)| Images: %d (%s) | Volumes: %d \U0001F5A5 CPU: %d | Memory: %s ",
352352
m.dockerVersion,
353353
len(m.dockerClient.Containers),
354+
m.dockerClient.GetAllContainersSize(),
354355
len(m.dockerClient.Images),
356+
m.dockerClient.GetAllImagesSize(),
355357
len(m.dockerClient.Volumes),
356358
m.cpuCores,
357359
m.ram,

0 commit comments

Comments
 (0)