docker

package module
v0.99.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainerEnvToMap

func ContainerEnvToMap(env []string) map[string]string

func MustNewAPIVersion added in v0.93.0

func MustNewAPIVersion(version string) string

MustNewAPIVersion evaluates version as a client api version and panics if invalid.

func NewAPIVersion added in v0.93.0

func NewAPIVersion(version string) (string, error)

func VersionIsValidAndGTE added in v0.93.0

func VersionIsValidAndGTE(version, gte string) error

VersionIsValidAndGTE evalutes version as a client api version and returns an error if invalid or less than gte. gte is assumed to be valid (easiest if result of MustNewAPIVersion on initialization)

Types

type Client

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

Client provides the core metric gathering functionality from the Docker Daemon. It retrieves container information in two forms to produce metric data: dtypes.ContainerJSON from client.ContainerInspect() for container information (id, name, hostname, labels, and env) and dtypes.StatsJSON from client.ContainerStats() for metric values.

func NewDockerClient

func NewDockerClient(config *Config, logger *zap.Logger, opts ...docker.Opt) (*Client, error)

func (*Client) ContainerEventLoop

func (dc *Client) ContainerEventLoop(ctx context.Context)

func (*Client) Containers

func (dc *Client) Containers() []Container

Containers provides a slice of Container to use for individual FetchContainerStats calls.

func (*Client) Events added in v0.39.0

func (dc *Client) Events(ctx context.Context, options dtypes.EventsOptions) (<-chan devents.Message, <-chan error)

Events exposes the underlying Docker clients Events channel. Caller should close the events channel by canceling the context. If an error occurs, processing stops and caller must reinvoke this method.

func (*Client) FetchContainerStats

func (dc *Client) FetchContainerStats(
	ctx context.Context,
	container Container,
) (dtypes.ContainerStats, error)

FetchContainerStats will query the desired container stats and return them as ContainerStats

func (*Client) FetchContainerStatsAsJSON

func (dc *Client) FetchContainerStatsAsJSON(
	ctx context.Context,
	container Container,
) (*dtypes.StatsJSON, error)

FetchContainerStatsAsJSON will query the desired container stats and return them as StatsJSON

func (*Client) InspectAndPersistContainer added in v0.39.0

func (dc *Client) InspectAndPersistContainer(ctx context.Context, cid string) (*dtypes.ContainerJSON, bool)

InspectAndPersistContainer queries inspect api and returns *ContainerJSON and true when container should be queried for stats, nil and false otherwise. Persists the container in the cache if container is running and not excluded.

func (*Client) LoadContainerList

func (dc *Client) LoadContainerList(ctx context.Context) error

LoadContainerList will load the initial running container maps for inspection and establishing which containers warrant stat gathering calls by the receiver.

func (*Client) RemoveContainer added in v0.39.0

func (dc *Client) RemoveContainer(cid string)

type Config

type Config struct {
	// The URL of the docker server. Default is "unix:///var/run/docker.sock"
	Endpoint string `mapstructure:"endpoint"`

	// The maximum amount of time to wait for docker API responses. Default is 5s
	Timeout time.Duration `mapstructure:"timeout"`

	// A list of filters whose matching images are to be excluded. Supports literals, globs, and regex.
	ExcludedImages []string `mapstructure:"excluded_images"`

	// Docker client API version.
	DockerAPIVersion string `mapstructure:"api_version"`
}

func NewConfig

func NewConfig(endpoint string, timeout time.Duration, excludedImages []string, apiVersion string) (*Config, error)

NewConfig creates a new config to be used when creating a docker client

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig creates a new config with default values to be used when creating a docker client

type Container

type Container struct {
	*dtypes.ContainerJSON
	EnvMap map[string]string
}

Container is client.ContainerInspect() response container stats and translated environment string map for potential labels.

Jump to

Keyboard shortcuts

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