Skip to content

Commit 31eeb3b

Browse files
qiutongsbobbypage
authored andcommitted
Count the size of logs towards TotalUsageBytes
1 parent 623dbc5 commit 31eeb3b

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

container/containerd/handler.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/containerd/containerd/errdefs"
2525
"golang.org/x/net/context"
26+
criapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
2627

2728
"github.com/google/cadvisor/container"
2829
"github.com/google/cadvisor/container/common"
@@ -36,6 +37,8 @@ type fsUsageProvider struct {
3637
ctx context.Context
3738
containerID string
3839
client ContainerdClient
40+
fsInfo fs.FsInfo
41+
logPath string
3942
}
4043

4144
type containerdContainerHandler struct {
@@ -129,8 +132,9 @@ func newContainerdContainerHandler(
129132
// Special container name for sandbox(pause)
130133
// It is defined in https://github.com/kubernetes/kubernetes/blob/master/pkg/kubelet/dockershim/naming.go#L50-L52
131134
containerName := "POD"
135+
var status *criapi.ContainerStatus
132136
if cntr.Labels["io.cri-containerd.kind"] != "sandbox" {
133-
status, err := client.ContainerStatus(ctx, id)
137+
status, err = client.ContainerStatus(ctx, id)
134138
if err != nil {
135139
return nil, err
136140
}
@@ -220,6 +224,9 @@ func newContainerdContainerHandler(
220224
ctx: ctx,
221225
client: client,
222226
containerID: id,
227+
// Path of logs, e.g. /var/log/pods/XXX
228+
logPath: status.LogPath,
229+
fsInfo: fsInfo,
223230
})
224231
}
225232

@@ -370,9 +377,17 @@ func (f *fsUsageProvider) Usage() (*common.FsUsage, error) {
370377
if err != nil {
371378
return nil, err
372379
}
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+
}
373388
return &common.FsUsage{
374389
BaseUsageBytes: stats.WritableLayer.UsedBytes.Value,
375-
TotalUsageBytes: stats.WritableLayer.UsedBytes.Value,
390+
TotalUsageBytes: stats.WritableLayer.UsedBytes.Value + logUsedBytes,
376391
InodeUsage: stats.WritableLayer.InodesUsed.Value,
377392
}, nil
378393
}

0 commit comments

Comments
 (0)