2018-02-05 21:05:59 +00:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2016-09-08 20:45:05 +00:00
|
|
|
|
|
|
|
import (
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2016-09-08 20:45:05 +00: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)
|
2019-02-11 12:26:12 +00:00
|
|
|
defer ensureReaderClosed(serverResp)
|
2016-09-08 20:45:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return du, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := json.NewDecoder(serverResp.body).Decode(&du); err != nil {
|
|
|
|
return du, fmt.Errorf("Error retrieving disk usage: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return du, nil
|
|
|
|
}
|