diff --git a/pkg/volume/metrics_du.go b/pkg/volume/metrics_du.go index 88a985d5ac2..1cae99c1073 100644 --- a/pkg/volume/metrics_du.go +++ b/pkg/volume/metrics_du.go @@ -25,7 +25,7 @@ import ( var _ MetricsProvider = &metricsDu{} // metricsDu represents a MetricsProvider that calculates the used and -// available Volume space by executing the "du" command and gathering +// available Volume space by calling fs.DiskUsage() and gathering // filesystem info for the Volume path. type metricsDu struct { // the directory path the volume is mounted to. @@ -46,7 +46,7 @@ func (md *metricsDu) GetMetrics() (*Metrics, error) { return metrics, NewNoPathDefinedError() } - err := md.runDu(metrics) + err := md.runDiskUsage(metrics) if err != nil { return metrics, err } @@ -64,9 +64,9 @@ func (md *metricsDu) GetMetrics() (*Metrics, error) { return metrics, nil } -// runDu executes the "du" command and writes the results to metrics.Used -func (md *metricsDu) runDu(metrics *Metrics) error { - used, err := fs.Du(md.path) +// runDiskUsage gets disk usage of md.path and writes the results to metrics.Used +func (md *metricsDu) runDiskUsage(metrics *Metrics) error { + used, err := fs.DiskUsage(md.path) if err != nil { return err } diff --git a/pkg/volume/util/fs/fs.go b/pkg/volume/util/fs/fs.go index bbb4b0105c5..a80a167eea7 100644 --- a/pkg/volume/util/fs/fs.go +++ b/pkg/volume/util/fs/fs.go @@ -54,7 +54,8 @@ func FsInfo(path string) (int64, int64, int64, int64, int64, int64, error) { return available, capacity, usage, inodes, inodesFree, inodesUsed, nil } -func Du(path string) (*resource.Quantity, error) { +// DiskUsage gets disk usage of specified path. +func DiskUsage(path string) (*resource.Quantity, error) { // Uses the same niceness level as cadvisor.fs does when running du // Uses -B 1 to always scale to a blocksize of 1 byte out, err := exec.Command("nice", "-n", "19", "du", "-s", "-B", "1", path).CombinedOutput() diff --git a/pkg/volume/util/fs/fs_unsupported.go b/pkg/volume/util/fs/fs_unsupported.go index b48e4fd20cb..340b4fdc225 100644 --- a/pkg/volume/util/fs/fs_unsupported.go +++ b/pkg/volume/util/fs/fs_unsupported.go @@ -29,7 +29,8 @@ func FsInfo(path string) (int64, int64, int64, int64, int64, int64, error) { return 0, 0, 0, 0, 0, 0, fmt.Errorf("FsInfo not supported for this build.") } -func Du(path string) (*resource.Quantity, error) { +// DiskUsage gets disk usage of specified path. +func DiskUsage(path string) (*resource.Quantity, error) { return nil, fmt.Errorf("Du not supported for this build.") } diff --git a/pkg/volume/util/fs/fs_windows.go b/pkg/volume/util/fs/fs_windows.go index 534604d2b2e..ea8c4784ae9 100644 --- a/pkg/volume/util/fs/fs_windows.go +++ b/pkg/volume/util/fs/fs_windows.go @@ -56,7 +56,8 @@ func FsInfo(path string) (int64, int64, int64, int64, int64, int64, error) { return freeBytesAvailable, totalNumberOfBytes, totalNumberOfBytes - freeBytesAvailable, 0, 0, 0, nil } -func Du(path string) (*resource.Quantity, error) { +// DiskUsage gets disk usage of specified path. +func DiskUsage(path string) (*resource.Quantity, error) { _, _, usage, _, _, _, err := FsInfo(path) if err != nil { return nil, err