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

Method statMem

cli/stat.go:174–226  ·  view source on GitHub ↗
(fs afero.Fs)

Source from the content-addressed store, hash-verified

172}
173
174func (*RootCmd) statMem(fs afero.Fs) *serpent.Command {
175 var (
176 hostArg bool
177 prefixArg string
178 st *clistat.Statter
179 formatter = cliui.NewOutputFormatter(cliui.TextFormat(), cliui.JSONFormat())
180 )
181 cmd := &serpent.Command{
182 Use: "mem",
183 Short: "Show memory usage, in gigabytes.",
184 Middleware: initStatterMW(&st, fs),
185 Options: serpent.OptionSet{
186 {
187 Flag: "host",
188 Value: serpent.BoolOf(&hostArg),
189 Description: "Force host memory measurement.",
190 },
191 {
192 Description: "SI Prefix for memory measurement.",
193 Default: clistat.PrefixHumanGibi,
194 Flag: "prefix",
195 Value: serpent.EnumOf(&prefixArg,
196 clistat.PrefixHumanKibi,
197 clistat.PrefixHumanMebi,
198 clistat.PrefixHumanGibi,
199 clistat.PrefixHumanTebi,
200 ),
201 },
202 },
203 Handler: func(inv *serpent.Invocation) error {
204 pfx := clistat.ParsePrefix(prefixArg)
205 var ms *clistat.Result
206 var err error
207 if ok, _ := st.IsContainerized(); ok && !hostArg {
208 ms, err = st.ContainerMemory(pfx)
209 } else {
210 ms, err = st.HostMemory(pfx)
211 }
212 if err != nil {
213 return err
214 }
215 out, err := formatter.Format(inv.Context(), ms)
216 if err != nil {
217 return err
218 }
219 _, err = fmt.Fprintln(inv.Stdout, out)
220 return err
221 },
222 }
223
224 formatter.AttachOptions(&cmd.Options)
225 return cmd
226}
227
228func (*RootCmd) statDisk(fs afero.Fs) *serpent.Command {
229 var (

Callers 1

statMethod · 0.95

Calls 10

NewOutputFormatterFunction · 0.92
TextFormatFunction · 0.92
JSONFormatFunction · 0.92
initStatterMWFunction · 0.85
IsContainerizedMethod · 0.65
ContainerMemoryMethod · 0.65
HostMemoryMethod · 0.65
FormatMethod · 0.65
ContextMethod · 0.65
AttachOptionsMethod · 0.65

Tested by

no test coverage detected