docker

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2018 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContainerName          = report.DockerContainerName
	ContainerCommand       = report.DockerContainerCommand
	ContainerPorts         = report.DockerContainerPorts
	ContainerCreated       = report.DockerContainerCreated
	ContainerNetworks      = report.DockerContainerNetworks
	ContainerIPs           = report.DockerContainerIPs
	ContainerHostname      = report.DockerContainerHostname
	ContainerIPsWithScopes = report.DockerContainerIPsWithScopes
	ContainerState         = report.DockerContainerState
	ContainerStateHuman    = report.DockerContainerStateHuman
	ContainerUptime        = report.DockerContainerUptime
	ContainerRestartCount  = report.DockerContainerRestartCount
	ContainerNetworkMode   = report.DockerContainerNetworkMode

	NetworkRxDropped = "network_rx_dropped"
	NetworkRxBytes   = "network_rx_bytes"
	NetworkRxErrors  = "network_rx_errors"
	NetworkTxPackets = "network_tx_packets"
	NetworkTxDropped = "network_tx_dropped"
	NetworkRxPackets = "network_rx_packets"
	NetworkTxErrors  = "network_tx_errors"
	NetworkTxBytes   = "network_tx_bytes"

	MemoryMaxUsage = "docker_memory_max_usage"
	MemoryUsage    = "docker_memory_usage"
	MemoryFailcnt  = "docker_memory_failcnt"
	MemoryLimit    = "docker_memory_limit"

	CPUPercpuUsage       = "docker_cpu_per_cpu_usage"
	CPUUsageInUsermode   = "docker_cpu_usage_in_usermode"
	CPUTotalUsage        = "docker_cpu_total_usage"
	CPUUsageInKernelmode = "docker_cpu_usage_in_kernelmode"
	CPUSystemCPUUsage    = "docker_cpu_system_cpu_usage"

	LabelPrefix = "docker_label_"
	EnvPrefix   = "docker_env_"
)

These constants are keys used in node metadata

View Source
const (
	StopContainer    = report.DockerStopContainer
	StartContainer   = report.DockerStartContainer
	RestartContainer = report.DockerRestartContainer
	PauseContainer   = report.DockerPauseContainer
	UnpauseContainer = report.DockerUnpauseContainer
	RemoveContainer  = report.DockerRemoveContainer
	AttachContainer  = report.DockerAttachContainer
	ExecContainer    = report.DockerExecContainer
	ResizeExecTTY    = "docker_resize_exec_tty"
)

Control IDs used by the docker integration.

View Source
const (
	CreateEvent            = "create"
	DestroyEvent           = "destroy"
	RenameEvent            = "rename"
	StartEvent             = "start"
	DieEvent               = "die"
	PauseEvent             = "pause"
	UnpauseEvent           = "unpause"
	NetworkConnectEvent    = "network:connect"
	NetworkDisconnectEvent = "network:disconnect"
)

Consts exported for testing.

View Source
const (
	ImageID          = report.DockerImageID
	ImageName        = report.DockerImageName
	ImageTag         = report.DockerImageTag
	ImageSize        = report.DockerImageSize
	ImageVirtualSize = report.DockerImageVirtualSize
	IsInHostNetwork  = report.DockerIsInHostNetwork
	ImageLabelPrefix = "docker_image_label_"
	ImageTableID     = "image_table"
	ServiceName      = report.DockerServiceName
	StackNamespace   = report.DockerStackNamespace
	DefaultNamespace = "No stack"
)

Keys for use in Node

View Source
const (
	ContainerID = report.DockerContainerID
	Name        = report.Name
)

Node metadata keys.

Variables

View Source
var (
	StateCreated    = "created"
	StateDead       = "dead"
	StateExited     = "exited"
	StatePaused     = "paused"
	StateRestarting = "restarting"
	StateRunning    = "running"
	StateDeleted    = "deleted"
)

These 'constants' are used for node states. We need to take pointers to them, so they are vars...

View Source
var (
	NewDockerClientStub = newDockerClient
	NewContainerStub    = NewContainer
)

Vars exported for testing.

View Source
var (
	ContainerMetadataTemplates = report.MetadataTemplates{
		ImageTag:              {ID: ImageTag, Label: "Image tag", From: report.FromLatest, Priority: 1},
		ImageName:             {ID: ImageName, Label: "Image name", From: report.FromLatest, Priority: 2},
		ContainerCommand:      {ID: ContainerCommand, Label: "Command", From: report.FromLatest, Priority: 3},
		ContainerStateHuman:   {ID: ContainerStateHuman, Label: "State", From: report.FromLatest, Priority: 4},
		ContainerUptime:       {ID: ContainerUptime, Label: "Uptime", From: report.FromLatest, Priority: 5, Datatype: report.Duration},
		ContainerRestartCount: {ID: ContainerRestartCount, Label: "Restart #", From: report.FromLatest, Priority: 6},
		ContainerNetworks:     {ID: ContainerNetworks, Label: "Networks", From: report.FromSets, Priority: 7},
		ContainerIPs:          {ID: ContainerIPs, Label: "IPs", From: report.FromSets, Priority: 8},
		ContainerPorts:        {ID: ContainerPorts, Label: "Ports", From: report.FromSets, Priority: 9},
		ContainerCreated:      {ID: ContainerCreated, Label: "Created", From: report.FromLatest, Datatype: report.DateTime, Priority: 10},
		ContainerID:           {ID: ContainerID, Label: "ID", From: report.FromLatest, Truncate: 12, Priority: 11},
	}

	ContainerMetricTemplates = report.MetricTemplates{
		CPUTotalUsage: {ID: CPUTotalUsage, Label: "CPU", Format: report.PercentFormat, Priority: 1},
		MemoryUsage:   {ID: MemoryUsage, Label: "Memory", Format: report.FilesizeFormat, Priority: 2},
	}

	ContainerImageMetadataTemplates = report.MetadataTemplates{
		report.Container: {ID: report.Container, Label: "# Containers", From: report.FromCounters, Datatype: report.Number, Priority: 2},
	}

	ContainerTableTemplates = report.TableTemplates{
		ImageTableID: {
			ID:    ImageTableID,
			Label: "Image",
			Type:  report.PropertyListType,
			FixedRows: map[string]string{

				ImageID:          " ID",
				ImageName:        " Name",
				ImageTag:         " Tag",
				ImageSize:        "Size",
				ImageVirtualSize: "Virtual size",
			},
		},
		LabelPrefix: {
			ID:     LabelPrefix,
			Label:  "Docker labels",
			Type:   report.PropertyListType,
			Prefix: LabelPrefix,
		},
		EnvPrefix: {
			ID:     EnvPrefix,
			Label:  "Environment variables",
			Type:   report.PropertyListType,
			Prefix: EnvPrefix,
		},
	}

	ContainerImageTableTemplates = report.TableTemplates{
		ImageLabelPrefix: {
			ID:     ImageLabelPrefix,
			Label:  "Docker labels",
			Type:   report.PropertyListType,
			Prefix: ImageLabelPrefix,
		},
	}

	ContainerControls = []report.Control{
		{
			ID:    AttachContainer,
			Human: "Attach",
			Icon:  "fa fa-desktop",
			Rank:  1,
		},
		{
			ID:    ExecContainer,
			Human: "Exec shell",
			Icon:  "fa fa-terminal",
			Rank:  2,
		},
		{
			ID:    StartContainer,
			Human: "Start",
			Icon:  "fa fa-play",
			Rank:  3,
		},
		{
			ID:    RestartContainer,
			Human: "Restart",
			Icon:  "fa fa-redo",
			Rank:  4,
		},
		{
			ID:    PauseContainer,
			Human: "Pause",
			Icon:  "fa fa-pause",
			Rank:  5,
		},
		{
			ID:    UnpauseContainer,
			Human: "Unpause",
			Icon:  "fa fa-play",
			Rank:  6,
		},
		{
			ID:    StopContainer,
			Human: "Stop",
			Icon:  "fa fa-stop",
			Rank:  7,
		},
		{
			ID:    RemoveContainer,
			Human: "Remove",
			Icon:  "far fa-trash-alt",
			Rank:  8,
		},
	}

	SwarmServiceMetadataTemplates = report.MetadataTemplates{
		ServiceName:    {ID: ServiceName, Label: "Service name", From: report.FromLatest, Priority: 0},
		StackNamespace: {ID: StackNamespace, Label: "Stack namespace", From: report.FromLatest, Priority: 1},
	}
)

Exposed for testing

View Source
var (
	NewProcessTreeStub = process.NewTree
)

These vars are exported for testing.

Functions

func ContainerIsStopped added in v0.14.0

func ContainerIsStopped(c Container) bool

ContainerIsStopped checks if the docker container is in one of our "stopped" states

func ExtractContainerIPs added in v0.7.0

func ExtractContainerIPs(nmd report.Node) []string

ExtractContainerIPs returns the list of container IPs given a Node from the Container topology.

func ExtractContainerIPsWithScopes added in v0.9.0

func ExtractContainerIPsWithScopes(nmd report.Node) []string

ExtractContainerIPsWithScopes returns the list of container IPs, prepended with scopes, given a Node from the Container topology.

func ImageNameTag added in v1.9.1

func ImageNameTag(imageName string) string

ImageNameTag splits the image name apart, returning the version tag, if possible

func ImageNameWithoutTag added in v1.9.1

func ImageNameWithoutTag(imageName string) string

ImageNameWithoutTag splits the image name apart, returning the name without the version, if possible

Types

type Client

type Client interface {
	ListContainers(docker_client.ListContainersOptions) ([]docker_client.APIContainers, error)
	InspectContainer(string) (*docker_client.Container, error)
	ListImages(docker_client.ListImagesOptions) ([]docker_client.APIImages, error)
	ListNetworks() ([]docker_client.Network, error)
	AddEventListener(chan<- *docker_client.APIEvents) error
	RemoveEventListener(chan *docker_client.APIEvents) error

	StopContainer(string, uint) error
	StartContainer(string, *docker_client.HostConfig) error
	RestartContainer(string, uint) error
	PauseContainer(string) error
	UnpauseContainer(string) error
	RemoveContainer(docker_client.RemoveContainerOptions) error
	AttachToContainerNonBlocking(docker_client.AttachToContainerOptions) (docker_client.CloseWaiter, error)
	CreateExec(docker_client.CreateExecOptions) (*docker_client.Exec, error)
	StartExecNonBlocking(string, docker_client.StartExecOptions) (docker_client.CloseWaiter, error)
	Stats(docker_client.StatsOptions) error
	ResizeExecTTY(id string, height, width int) error
}

Client interface for mocking.

type Container

type Container interface {
	UpdateState(*docker.Container)

	ID() string
	Image() string
	PID() int
	Hostname() string
	GetNode() report.Node
	State() string
	StateString() string
	HasTTY() bool
	Container() *docker.Container
	StartGatheringStats(StatsGatherer) error
	StopGatheringStats()
	NetworkMode() (string, bool)
	NetworkInfo([]net.IP) report.Sets
}

Container represents a Docker container

func NewContainer

func NewContainer(c *docker.Container, hostID string, noCommandLineArguments bool, noEnvironmentVariables bool) Container

NewContainer creates a new Container

type ContainerUpdateWatcher added in v0.10.0

type ContainerUpdateWatcher func(report.Node)

ContainerUpdateWatcher is the type of functions that get called when containers are updated.

type Registry

type Registry interface {
	Stop()
	LockedPIDLookup(f func(func(int) Container))
	WalkContainers(f func(Container))
	WalkImages(f func(docker_client.APIImages))
	WalkNetworks(f func(docker_client.Network))
	WatchContainerUpdates(ContainerUpdateWatcher)
	GetContainer(string) (Container, bool)
	GetContainerByPrefix(string) (Container, bool)
	GetContainerImage(string) (docker_client.APIImages, bool)
}

Registry keeps track of running docker containers and their images

func NewRegistry

func NewRegistry(options RegistryOptions) (Registry, error)

NewRegistry returns a usable Registry. Don't forget to Stop it.

type RegistryOptions added in v1.3.0

type RegistryOptions struct {
	Interval               time.Duration
	Pipes                  controls.PipeClient
	CollectStats           bool
	HostID                 string
	HandlerRegistry        *controls.HandlerRegistry
	DockerEndpoint         string
	NoCommandLineArguments bool
	NoEnvironmentVariables bool
}

RegistryOptions are used to initialize the Registry

type Reporter

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

Reporter generate Reports containing Container and ContainerImage topologies

func NewReporter

func NewReporter(registry Registry, hostID string, probeID string, probe *probe.Probe) *Reporter

NewReporter makes a new Reporter

func (*Reporter) ContainerUpdated added in v0.10.0

func (r *Reporter) ContainerUpdated(n report.Node)

ContainerUpdated should be called whenever a container is updated.

func (Reporter) Name added in v0.10.0

func (Reporter) Name() string

Name of this reporter, for metrics gathering

func (*Reporter) Report

func (r *Reporter) Report() (report.Report, error)

Report generates a Report containing Container and ContainerImage topologies

type StatsGatherer added in v1.0.0

type StatsGatherer interface {
	Stats(docker.StatsOptions) error
}

StatsGatherer gathers container stats

type Tagger

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

Tagger is a tagger that tags Docker container information to process nodes that have a PID. It also populates the SwarmService topology if any of the associated docker labels are present.

func NewTagger

func NewTagger(registry Registry, procWalker process.Walker) *Tagger

NewTagger returns a usable Tagger.

func (Tagger) Name added in v0.10.0

func (Tagger) Name() string

Name of this tagger, for metrics gathering

func (*Tagger) Tag

func (t *Tagger) Tag(r report.Report) (report.Report, error)

Tag implements Tagger.

Jump to

Keyboard shortcuts

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