Skip to content

Commit 18f4942

Browse files
committed
add stat memory
1 parent d6029b4 commit 18f4942

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cli/stat.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ func (*RootCmd) stat() *clibase.Cmd {
5050
} else {
5151
sr.HostCPU = cs
5252
}
53+
if ms, err := statMem(hi); err != nil {
54+
return err
55+
} else {
56+
sr.HostMemory = ms
57+
}
5358
out, err := formatter.Format(inv.Context(), []statsRow{sr})
5459
if err != nil {
5560
return err
@@ -85,6 +90,19 @@ func statCPU(hi sysinfotypes.Host, interval time.Duration) (*stat, error) {
8590
return s, nil
8691
}
8792

93+
func statMem(hi sysinfotypes.Host) (*stat, error) {
94+
s := &stat{
95+
Unit: "GB",
96+
}
97+
hm, err := hi.Memory()
98+
if err != nil {
99+
return nil, err
100+
}
101+
s.Total = float64(hm.Total) / 1024 / 1024 / 1024
102+
s.Used = float64(hm.Used) / 1024 / 1024 / 1024
103+
return s, nil
104+
}
105+
88106
type statsRow struct {
89107
HostCPU *stat `json:"host_cpu" table:"host_cpu,default_sort"`
90108
HostMemory *stat `json:"host_memory" table:"host_memory"`

0 commit comments

Comments
 (0)