2018-02-05 16:05:59 -05:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2016-09-08 16:45:05 -04:00
|
|
|
|
|
|
|
import (
|
2018-04-19 18:30:59 -04:00
|
|
|
"context"
|
2016-09-08 16:45:05 -04:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DiskUsage requests the current data usage from the daemon
|
|
|
|
func (cli *Client) DiskUsage(ctx context.Context) (types.DiskUsage, error) {
|
|
|
|
var du types.DiskUsage
|
|
|
|
|
|
|
|
serverResp, err := cli.get(ctx, "/system/df", nil, nil)
|
|
|
|
if err != nil {
|
|
|
|
return du, err
|
|
|
|
}
|
|
|
|
defer ensureReaderClosed(serverResp)
|
|
|
|
|
|
|
|
if err := json.NewDecoder(serverResp.body).Decode(&du); err != nil {
|
|
|
|
return du, fmt.Errorf("Error retrieving disk usage: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return du, nil
|
|
|
|
}
|