Rename Du() to DiskUsage() for more expressive
This commit is contained in:
parent
7cbee06a00
commit
66da2ddcd0
@ -25,7 +25,7 @@ import (
|
|||||||
var _ MetricsProvider = &metricsDu{}
|
var _ MetricsProvider = &metricsDu{}
|
||||||
|
|
||||||
// metricsDu represents a MetricsProvider that calculates the used and
|
// 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.
|
// filesystem info for the Volume path.
|
||||||
type metricsDu struct {
|
type metricsDu struct {
|
||||||
// the directory path the volume is mounted to.
|
// the directory path the volume is mounted to.
|
||||||
@ -46,7 +46,7 @@ func (md *metricsDu) GetMetrics() (*Metrics, error) {
|
|||||||
return metrics, NewNoPathDefinedError()
|
return metrics, NewNoPathDefinedError()
|
||||||
}
|
}
|
||||||
|
|
||||||
err := md.runDu(metrics)
|
err := md.runDiskUsage(metrics)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return metrics, err
|
return metrics, err
|
||||||
}
|
}
|
||||||
@ -64,9 +64,9 @@ func (md *metricsDu) GetMetrics() (*Metrics, error) {
|
|||||||
return metrics, nil
|
return metrics, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// runDu executes the "du" command and writes the results to metrics.Used
|
// runDiskUsage gets disk usage of md.path and writes the results to metrics.Used
|
||||||
func (md *metricsDu) runDu(metrics *Metrics) error {
|
func (md *metricsDu) runDiskUsage(metrics *Metrics) error {
|
||||||
used, err := fs.Du(md.path)
|
used, err := fs.DiskUsage(md.path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
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 the same niceness level as cadvisor.fs does when running du
|
||||||
// Uses -B 1 to always scale to a blocksize of 1 byte
|
// 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()
|
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.")
|
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.")
|
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
|
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)
|
_, _, usage, _, _, _, err := FsInfo(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user