@@ -23,6 +23,7 @@ import (
23
23
24
24
"github.com/containerd/containerd/errdefs"
25
25
"golang.org/x/net/context"
26
+ criapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
26
27
27
28
"github.com/google/cadvisor/container"
28
29
"github.com/google/cadvisor/container/common"
@@ -36,6 +37,8 @@ type fsUsageProvider struct {
36
37
ctx context.Context
37
38
containerID string
38
39
client ContainerdClient
40
+ fsInfo fs.FsInfo
41
+ logPath string
39
42
}
40
43
41
44
type containerdContainerHandler struct {
@@ -129,8 +132,9 @@ func newContainerdContainerHandler(
129
132
// Special container name for sandbox(pause)
130
133
// It is defined in https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/dockershim/naming.go#L50-L52
131
134
containerName := "POD"
135
+ var status * criapi.ContainerStatus
132
136
if cntr .Labels ["io.cri-containerd.kind" ] != "sandbox" {
133
- status , err : = client .ContainerStatus (ctx , id )
137
+ status , err = client .ContainerStatus (ctx , id )
134
138
if err != nil {
135
139
return nil , err
136
140
}
@@ -220,6 +224,9 @@ func newContainerdContainerHandler(
220
224
ctx : ctx ,
221
225
client : client ,
222
226
containerID : id ,
227
+ // Path of logs, e.g. /var/log/pods/XXX
228
+ logPath : status .LogPath ,
229
+ fsInfo : fsInfo ,
223
230
})
224
231
}
225
232
@@ -370,9 +377,17 @@ func (f *fsUsageProvider) Usage() (*common.FsUsage, error) {
370
377
if err != nil {
371
378
return nil , err
372
379
}
380
+ var logUsedBytes uint64
381
+ if f .logPath != "" {
382
+ logUsage , err := f .fsInfo .GetDirUsage (f .logPath )
383
+ if err != nil {
384
+ return nil , err
385
+ }
386
+ logUsedBytes = logUsage .Bytes
387
+ }
373
388
return & common.FsUsage {
374
389
BaseUsageBytes : stats .WritableLayer .UsedBytes .Value ,
375
- TotalUsageBytes : stats .WritableLayer .UsedBytes .Value ,
390
+ TotalUsageBytes : stats .WritableLayer .UsedBytes .Value + logUsedBytes ,
376
391
InodeUsage : stats .WritableLayer .InodesUsed .Value ,
377
392
}, nil
378
393
}
0 commit comments