File tree 2 files changed +20
-6
lines changed
agent/proto/resourcesmonitor
2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -13,19 +13,29 @@ type Fetcher interface {
13
13
14
14
type fetcher struct {
15
15
* clistat.Statter
16
+ isContainerized bool
16
17
}
17
18
18
19
//nolint:revive
19
20
func NewFetcher (f * clistat.Statter ) * fetcher {
20
- return & fetcher {
21
- f ,
22
- }
21
+ isContainerized , _ := f . IsContainerized ()
22
+
23
+ return & fetcher { f , isContainerized }
23
24
}
24
25
25
26
func (f * fetcher ) FetchMemory () (total int64 , used int64 , err error ) {
26
- mem , err := f .HostMemory (clistat .PrefixDefault )
27
- if err != nil {
28
- return 0 , 0 , xerrors .Errorf ("failed to fetch memory: %w" , err )
27
+ var mem * clistat.Result
28
+
29
+ if f .isContainerized {
30
+ mem , err = f .ContainerMemory (clistat .PrefixDefault )
31
+ if err != nil {
32
+ return 0 , 0 , xerrors .Errorf ("failed to fetch memory: %w" , err )
33
+ }
34
+ } else {
35
+ mem , err = f .HostMemory (clistat .PrefixDefault )
36
+ if err != nil {
37
+ return 0 , 0 , xerrors .Errorf ("failed to fetch memory: %w" , err )
38
+ }
29
39
}
30
40
31
41
if mem .Total == nil {
Original file line number Diff line number Diff line change @@ -16,6 +16,10 @@ const (
16
16
kubernetesDefaultServiceAccountToken = "/var/run/secrets/kubernetes.io/serviceaccount/token" //nolint:gosec
17
17
)
18
18
19
+ func (s * Statter ) IsContainerized () (ok bool , err error ) {
20
+ return IsContainerized (s .fs )
21
+ }
22
+
19
23
// IsContainerized returns whether the host is containerized.
20
24
// This is adapted from https://github.com/elastic/go-sysinfo/tree/main/providers/linux/container.go#L31
21
25
// with modifications to support Sysbox containers.
You can’t perform that action at this time.
0 commit comments