summaryrefslogtreecommitdiff
path: root/vendor/github.com/fsouza/go-dockerclient/system.go
blob: 46b9faf00e2b04425b5eb8bd8563b4466ea17d6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package docker

import (
	"context"
	"encoding/json"
	"net/http"
)

// VolumeUsageData represents usage data from the docker system api
// More Info Here https://dockr.ly/2PNzQyO
type VolumeUsageData struct {

	// The number of containers referencing this volume. This field
	// is set to `-1` if the reference-count is not available.
	//
	// Required: true
	RefCount int64 `json:"RefCount"`

	// Amount of disk space used by the volume (in bytes). This information
	// is only available for volumes created with the `"local"` volume
	// driver. For volumes created with other volume drivers, this field
	// is set to `-1` ("not available")
	//
	// Required: true
	Size int64 `json:"Size"`
}

// ImageSummary represents data about what images are
// currently known to docker
// More Info Here https://dockr.ly/2PNzQyO
type ImageSummary struct {
	Containers  int64             `json:"Containers"`
	Created     int64             `json:"Created"`
	ID          string            `json:"Id"`
	Labels      map[string]string `json:"Labels"`
	ParentID    string            `json:"ParentId"`
	RepoDigests []string          `json:"RepoDigests"`
	RepoTags    []string          `json:"RepoTags"`
	SharedSize  int64             `json:"SharedSize"`
	Size        int64             `json:"Size"`
	VirtualSize int64             `json:"VirtualSize"`
}

// DiskUsage holds information about what docker is using disk space on.
// More Info Here https://dockr.ly/2PNzQyO
type DiskUsage struct {
	LayersSize int64
	Images     []*ImageSummary
	Containers []*APIContainers
	Volumes    []*Volume
}

// DiskUsageOptions only contains a context for canceling.
type DiskUsageOptions struct {
	Context context.Context
}

// DiskUsage returns a *DiskUsage describing what docker is using disk on.
//
// More Info Here https://dockr.ly/2PNzQyO
func (c *Client) DiskUsage(opts DiskUsageOptions) (*DiskUsage, error) {
	path := "/system/df"
	resp, err := c.do(http.MethodGet, path, doOptions{context: opts.Context})
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	var du *DiskUsage
	if err := json.NewDecoder(resp.Body).Decode(&du); err != nil {
		return nil, err
	}
	return du, nil
}