github.com/opsramp/moby@v1.13.1/client/disk_usage.go (about)

     1  package client
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	"golang.org/x/net/context"
     9  )
    10  
    11  // DiskUsage requests the current data usage from the daemon
    12  func (cli *Client) DiskUsage(ctx context.Context) (types.DiskUsage, error) {
    13  	var du types.DiskUsage
    14  
    15  	serverResp, err := cli.get(ctx, "/system/df", nil, nil)
    16  	if err != nil {
    17  		return du, err
    18  	}
    19  	defer ensureReaderClosed(serverResp)
    20  
    21  	if err := json.NewDecoder(serverResp.body).Decode(&du); err != nil {
    22  		return du, fmt.Errorf("Error retrieving disk usage: %v", err)
    23  	}
    24  
    25  	return du, nil
    26  }