Commit 66da2ddc authored by Pengfei Ni's avatar Pengfei Ni

Rename Du() to DiskUsage() for more expressive

parent 7cbee06a
......@@ -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
}
......
......@@ -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()
......
......@@ -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.")
}
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment