MCPcopy Index your code
hub / github.com/coder/coder / stat

Method stat

cli/stat.go:29–131  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27}
28
29func (r *RootCmd) stat() *serpent.Command {
30 var (
31 st *clistat.Statter
32 fs = afero.NewReadOnlyFs(afero.NewOsFs())
33 formatter = cliui.NewOutputFormatter(
34 cliui.TableFormat([]statsRow{}, []string{
35 "host cpu",
36 "host memory",
37 "home disk",
38 "container cpu",
39 "container memory",
40 }),
41 cliui.JSONFormat(),
42 )
43 )
44 cmd := &serpent.Command{
45 Use: "stat",
46 Short: "Show resource usage for the current workspace.",
47 Middleware: initStatterMW(&st, fs),
48 Children: []*serpent.Command{
49 r.statCPU(fs),
50 r.statMem(fs),
51 r.statDisk(fs),
52 },
53 Handler: func(inv *serpent.Invocation) error {
54 var sr statsRow
55
56 // Get CPU measurements first.
57 hostErr := make(chan error, 1)
58 containerErr := make(chan error, 1)
59 go func() {
60 defer close(hostErr)
61 cs, err := st.HostCPU()
62 if err != nil {
63 hostErr <- err
64 return
65 }
66 sr.HostCPU = cs
67 }()
68 go func() {
69 defer close(containerErr)
70 if ok, _ := st.IsContainerized(); !ok {
71 // don't error if we're not in a container
72 return
73 }
74 cs, err := st.ContainerCPU()
75 if err != nil {
76 containerErr <- err
77 return
78 }
79 sr.ContainerCPU = cs
80 }()
81
82 if err := <-hostErr; err != nil {
83 return err
84 }
85 if err := <-containerErr; err != nil {
86 return err

Callers 1

CoreSubcommandsMethod · 0.95

Calls 14

statCPUMethod · 0.95
statMemMethod · 0.95
statDiskMethod · 0.95
NewOutputFormatterFunction · 0.92
TableFormatFunction · 0.92
JSONFormatFunction · 0.92
initStatterMWFunction · 0.85
IsContainerizedMethod · 0.65
HostMemoryMethod · 0.65
DiskMethod · 0.65
ContainerMemoryMethod · 0.65
FormatMethod · 0.65

Tested by

no test coverage detected