Documentation ¶
Overview ¶
Package docker contains few helper functions copied from https://github.com/docker/cli/blob/master/cli/command/container/stats_helpers.go
Index ¶
- Constants
- Variables
- func CalculateCPUPercentUnix(previousCPU, previousSystem uint64, v *types.StatsJSON) float64
- func CalculateMemPercentUnixNoCache(limit float64, usedNoCache float64) float64
- func CalculateMemUsageUnixNoCache(mem types.MemoryStats) float64
- type Client
- type Docker
- type SocketClient
- func (c *SocketClient) Close() error
- func (c *SocketClient) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
- func (c *SocketClient) ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)
- func (c *SocketClient) ContainerStats(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error)
- func (c *SocketClient) Info(ctx context.Context) (types.Info, error)
- func (c *SocketClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error)
- func (c *SocketClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
- func (c *SocketClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)
Constants ¶
const ( KB = 1000 MB = 1000 * KB GB = 1000 * MB TB = 1000 * GB PB = 1000 * TB )
KB, MB, GB, TB, PB...human friendly
Variables ¶
var NodeList = []swarm.Node{ { ID: "0cl4jturcyd1ks3fwpd010kor", Status: swarm.NodeStatus{ State: "ready", }, }, { ID: "0cl4jturcyd1ks3fwpd010kor", Status: swarm.NodeStatus{ State: "ready", }, }, }
var ServiceList = []swarm.Service{ { ID: "qolkls9g5iasdiuihcyz9rnx2", Spec: swarm.ServiceSpec{ Annotations: swarm.Annotations{ Name: "test1", }, Mode: swarm.ServiceMode{ Replicated: &swarm.ReplicatedService{ Replicas: &two, }, }, }, }, { ID: "qolkls9g5iasdiuihcyz9rn3", Spec: swarm.ServiceSpec{ Annotations: swarm.Annotations{ Name: "test2", }, Mode: swarm.ServiceMode{ Global: &swarm.GlobalService{}, }, }, }, }
var TaskList = []swarm.Task{ { ID: "kwh0lv7hwwbh", ServiceID: "qolkls9g5iasdiuihcyz9rnx2", NodeID: "0cl4jturcyd1ks3fwpd010kor", Status: swarm.TaskStatus{ State: "running", }, DesiredState: "running", }, { ID: "u78m5ojbivc3", ServiceID: "qolkls9g5iasdiuihcyz9rnx2", NodeID: "0cl4jturcyd1ks3fwpd010kor", Status: swarm.TaskStatus{ State: "running", }, DesiredState: "running", }, { ID: "1n1uilkhr98l", ServiceID: "qolkls9g5iasdiuihcyz9rn3", NodeID: "0cl4jturcyd1ks3fwpd010kor", Status: swarm.TaskStatus{ State: "running", }, DesiredState: "running", }, }
Functions ¶
func CalculateCPUPercentUnix ¶ added in v1.14.0
func CalculateMemPercentUnixNoCache ¶ added in v1.14.0
func CalculateMemUsageUnixNoCache ¶ added in v1.14.0
func CalculateMemUsageUnixNoCache(mem types.MemoryStats) float64
CalculateMemUsageUnixNoCache calculate memory usage of the container. Cache is intentionally excluded to avoid misinterpretation of the output.
On Docker 19.03 and older, the result is `mem.Usage - mem.Stats["cache"]`. On new docker with cgroup v1 host, the result is `mem.Usage - mem.Stats["total_inactive_file"]`. On new docker with cgroup v2 host, the result is `mem.Usage - mem.Stats["inactive_file"]`.
This definition is designed to be consistent with past values and the latest docker CLI * https://github.com/docker/cli/blob/6e2838e18645e06f3e4b6c5143898ccc44063e3b/cli/command/container/stats_helpers.go#L239
Types ¶
type Client ¶ added in v1.14.0
type Client interface { Info(ctx context.Context) (types.Info, error) ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error) ContainerStats(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error) Close() error }
func NewEnvClient ¶ added in v1.14.0
type Docker ¶
type Docker struct { Endpoint string ContainerNames []string `toml:"container_names" deprecated:"1.4.0;use 'container_name_include' instead"` GatherServices bool `toml:"gather_services"` Timeout config.Duration PerDevice bool `toml:"perdevice" deprecated:"1.18.0;use 'perdevice_include' instead"` PerDeviceInclude []string `toml:"perdevice_include"` Total bool `toml:"total" deprecated:"1.18.0;use 'total_include' instead"` TotalInclude []string `toml:"total_include"` TagEnvironment []string `toml:"tag_env"` LabelInclude []string `toml:"docker_label_include"` LabelExclude []string `toml:"docker_label_exclude"` ContainerInclude []string `toml:"container_name_include"` ContainerExclude []string `toml:"container_name_exclude"` ContainerStateInclude []string `toml:"container_state_include"` ContainerStateExclude []string `toml:"container_state_exclude"` IncludeSourceTag bool `toml:"source_tag"` Log telegraf.Logger tlsint.ClientConfig // contains filtered or unexported fields }
Docker object
func (*Docker) Gather ¶
func (d *Docker) Gather(acc telegraf.Accumulator) error
Gather metrics from the docker server.
func (*Docker) SampleConfig ¶
type SocketClient ¶ added in v1.14.0
type SocketClient struct {
// contains filtered or unexported fields
}
func (*SocketClient) Close ¶ added in v1.19.0
func (c *SocketClient) Close() error
func (*SocketClient) ContainerInspect ¶ added in v1.14.0
func (c *SocketClient) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)
func (*SocketClient) ContainerList ¶ added in v1.14.0
func (c *SocketClient) ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)
func (*SocketClient) ContainerStats ¶ added in v1.14.0
func (c *SocketClient) ContainerStats(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error)
func (*SocketClient) NodeList ¶ added in v1.14.0
func (c *SocketClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error)
func (*SocketClient) ServiceList ¶ added in v1.14.0
func (c *SocketClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
func (*SocketClient) TaskList ¶ added in v1.14.0
func (c *SocketClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)