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

Method FetchMemory

agent/proto/resourcesmonitor/fetcher.go:36–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

34}
35
36func (f *fetcher) FetchMemory() (total int64, used int64, err error) {
37 var mem *clistat.Result
38
39 if f.isContainerized {
40 mem, err = f.ContainerMemory(clistat.PrefixDefault)
41 if err != nil {
42 return 0, 0, xerrors.Errorf("fetch container memory: %w", err)
43 }
44
45 // A container might not have a memory limit set. If this
46 // happens we want to fallback to querying the host's memory
47 // to know what the total memory is on the host.
48 if mem.Total == nil {
49 hostMem, err := f.HostMemory(clistat.PrefixDefault)
50 if err != nil {
51 return 0, 0, xerrors.Errorf("fetch host memory: %w", err)
52 }
53
54 mem.Total = hostMem.Total
55 }
56 } else {
57 mem, err = f.HostMemory(clistat.PrefixDefault)
58 if err != nil {
59 return 0, 0, xerrors.Errorf("fetch host memory: %w", err)
60 }
61 }
62
63 if mem.Total == nil {
64 return 0, 0, xerrors.New("memory total is nil - can not fetch memory")
65 }
66
67 return int64(*mem.Total), int64(mem.Used), nil
68}
69
70func (f *fetcher) FetchVolume(volume string) (total int64, used int64, err error) {
71 vol, err := f.Disk(clistat.PrefixDefault, volume)

Callers

nothing calls this directly

Calls 4

ContainerMemoryMethod · 0.65
HostMemoryMethod · 0.65
NewMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected