Skip to content

Commit 3643407

Browse files
committed
remove uptime stat as it is trivial to implement in bash
1 parent be7ba72 commit 3643407

File tree

4 files changed

+1
-45
lines changed

4 files changed

+1
-45
lines changed

cli/clistat/container.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build !linux
2-
31
package clistat
42

53
import (

cli/clistat/stat.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -127,28 +127,3 @@ func (s *Statter) HostMemory() (*Result, error) {
127127
r.Used = float64(hm.Used) / 1024 / 1024 / 1024
128128
return r, nil
129129
}
130-
131-
// Uptime returns the uptime of the host, in seconds.
132-
// If the host is containerized, this will return the uptime of the container
133-
// by checking /proc/1/stat.
134-
func (s *Statter) Uptime() (*Result, error) {
135-
r := &Result{
136-
Unit: "minutes",
137-
Total: nil, // Is time a finite quantity? For this purpose, no.
138-
}
139-
140-
if ok, err := IsContainerized(s.fs); err == nil && ok {
141-
procStat, err := sysinfo.Process(1)
142-
if err != nil {
143-
return nil, xerrors.Errorf("get pid 1 info: %w", err)
144-
}
145-
procInfo, err := procStat.Info()
146-
if err != nil {
147-
return nil, xerrors.Errorf("get pid 1 stat: %w", err)
148-
}
149-
r.Used = time.Since(procInfo.StartTime).Minutes()
150-
return r, nil
151-
}
152-
r.Used = s.hi.Info().Uptime().Minutes()
153-
return r, nil
154-
}

cli/clistat/stat_internal_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@ func TestStatter(t *testing.T) {
7575
assert.NotZero(t, disk.Total)
7676
assert.NotZero(t, disk.Unit)
7777
})
78-
79-
t.Run("Uptime", func(t *testing.T) {
80-
t.Parallel()
81-
uptime, err := s.Uptime()
82-
require.NoError(t, err)
83-
assert.NotZero(t, uptime.Used)
84-
assert.Zero(t, uptime.Total)
85-
assert.Equal(t, "minutes", uptime.Unit)
86-
})
8778
})
8879

8980
t.Run("CGroupV1", func(t *testing.T) {

cli/stat.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
func (*RootCmd) stat() *clibase.Cmd {
1616
fs := afero.NewReadOnlyFs(afero.NewOsFs())
17-
defaultCols := []string{"host_cpu", "host_memory", "home_disk", "uptime"}
17+
defaultCols := []string{"host_cpu", "host_memory", "home_disk"}
1818
if ok, err := clistat.IsContainerized(fs); err == nil && ok {
1919
// If running in a container, we assume that users want to see these first. Prepend.
2020
defaultCols = append([]string{"container_cpu", "container_memory"}, defaultCols...)
@@ -68,13 +68,6 @@ func (*RootCmd) stat() *clibase.Cmd {
6868
}
6969
sr.Disk = ds
7070

71-
// Uptime is calculated either based on the host or the container, depending.
72-
us, err := st.Uptime()
73-
if err != nil {
74-
return err
75-
}
76-
sr.Uptime = us
77-
7871
// Container-only stats.
7972
if ok, err := clistat.IsContainerized(fs); err == nil && ok {
8073
cs, err := st.ContainerCPU()
@@ -108,5 +101,4 @@ type statsRow struct {
108101
Disk *clistat.Result `json:"home_disk" table:"home_disk"`
109102
ContainerCPU *clistat.Result `json:"container_cpu" table:"container_cpu"`
110103
ContainerMemory *clistat.Result `json:"container_memory" table:"container_memory"`
111-
Uptime *clistat.Result `json:"uptime" table:"uptime"`
112104
}

0 commit comments

Comments
 (0)