docker

package
v0.0.0-...-5655933 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2023 License: MIT Imports: 22 Imported by: 0

README

docker

forked from telegraf/inputs.docker

change

  1. Using container_id as label not field
  2. Some metrics have been deleted

容器ID标签

通过下面两个配置来控制 container_id 这个标签:

container_id_label_enable = true
container_id_label_short_style = false

默认 container_id_label_enable 设置为 true,表示启用,即会把容器ID放到标签里,container_id_label_short_style 是短格式,容器ID很长,如果把 short_style 设置为 true,就会只截取前面12位

权限问题

Categraf 最好是用 root 账号来运行,否则,请求 docker.sock 可能会遇到权限问题,需要把 Categraf 的运行账号,加到 docker group 中,假设 Categraf 使用 categraf 账号运行:

sudo usermod -aG docker categraf

运行在容器里

如果 Categraf 运行在容器中,docker 的 unix socket 就需要挂到 Categraf 的容器里,比如通过 -v /var/run/docker.sock:/var/run/docker.sock 这样的参数来启动 Categraf 的容器。如果是在 compose 环境下,也可以在 docker compose 配置中加上 volume 的配置:

volumes:
  - /var/run/docker.sock:/var/run/docker.sock

停用该插件

  • 方法一:把 input.docker 目录改个别的名字,不用 input. 打头
  • 方法二:docker.toml 中的 endpoint 配置留空

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

View Source
const (
	KB = 1000
	MB = 1000 * KB
	GB = 1000 * MB
	TB = 1000 * GB
	PB = 1000 * TB
)

KB, MB, GB, TB, PB...human friendly

Variables

This section is empty.

Functions

func CalculateCPUPercentUnix

func CalculateCPUPercentUnix(previousCPU, previousSystem uint64, v *types.StatsJSON) float64

func CalculateMemPercentUnixNoCache

func CalculateMemPercentUnixNoCache(limit float64, usedNoCache float64) float64

func CalculateMemUsageUnixNoCache

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

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)
	Ping(ctx context.Context) (types.Ping, 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 NewClient

func NewClient(host string, tlsConfig *tls.Config) (Client, error)

func NewEnvClient

func NewEnvClient() (Client, error)

type Docker

type Docker struct {
	config.PluginConfig
	Instances []*Instance `toml:"instances"`
}

func (*Docker) Clone

func (d *Docker) Clone() inputs.Input

func (*Docker) GetInstances

func (d *Docker) GetInstances() []inputs.Instance

func (Docker) Name

func (c Docker) Name() string

type Instance

type Instance struct {
	config.InstanceConfig

	Endpoint                   string   `toml:"endpoint"`
	GatherServices             bool     `toml:"gather_services"`
	GatherExtendMemstats       bool     `toml:"gather_extend_memstats"`
	ContainerIDLabelEnable     bool     `toml:"container_id_label_enable"`
	ContainerIDLabelShortStyle bool     `toml:"container_id_label_short_style"`
	PerDeviceInclude           []string `toml:"perdevice_include"`
	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"`

	Timeout config.Duration
	tlsx.ClientConfig
	// contains filtered or unexported fields
}

func (*Instance) Gather

func (ins *Instance) Gather(slist *itypes.SampleList)

func (*Instance) Init

func (ins *Instance) Init() error

type SocketClient

type SocketClient struct {
	// contains filtered or unexported fields
}

func (*SocketClient) Close

func (c *SocketClient) Close() error

func (*SocketClient) ContainerInspect

func (c *SocketClient) ContainerInspect(ctx context.Context, containerID string) (types.ContainerJSON, error)

func (*SocketClient) ContainerList

func (c *SocketClient) ContainerList(ctx context.Context, options types.ContainerListOptions) ([]types.Container, error)

func (*SocketClient) ContainerStats

func (c *SocketClient) ContainerStats(ctx context.Context, containerID string, stream bool) (types.ContainerStats, error)

func (*SocketClient) Info

func (c *SocketClient) Info(ctx context.Context) (types.Info, error)

func (*SocketClient) NodeList

func (c *SocketClient) NodeList(ctx context.Context, options types.NodeListOptions) ([]swarm.Node, error)

func (*SocketClient) Ping

func (c *SocketClient) Ping(ctx context.Context) (types.Ping, error)

func (*SocketClient) ServiceList

func (c *SocketClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)

func (*SocketClient) TaskList

func (c *SocketClient) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL