Documentation ¶
Index ¶
- Constants
- Variables
- func ContainerIsStopped(c Container) bool
- func ExtractContainerIPs(nmd report.Node) []string
- func ExtractContainerIPsWithScopes(nmd report.Node) []string
- func ImageNameWithoutVersion(name string) string
- type Client
- type ClientConn
- type Container
- type ContainerUpdateWatcher
- type Registry
- type Reporter
- type Tagger
Constants ¶
const ( ContainerName = "docker_container_name" ContainerCommand = "docker_container_command" ContainerPorts = "docker_container_ports" ContainerCreated = "docker_container_created" ContainerNetworks = "docker_container_networks" ContainerIPs = "docker_container_ips" ContainerHostname = "docker_container_hostname" ContainerIPsWithScopes = "docker_container_ips_with_scopes" ContainerState = "docker_container_state" ContainerStateHuman = "docker_container_state_human" ContainerUptime = "docker_container_uptime" ContainerRestartCount = "docker_container_restart_count" ContainerNetworkMode = "docker_container_network_mode" 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" NetworkModeHost = "host" LabelPrefix = "docker_label_" EnvPrefix = "docker_env_" )
These constants are keys used in node metadata
const ( StopContainer = "docker_stop_container" StartContainer = "docker_start_container" RestartContainer = "docker_restart_container" PauseContainer = "docker_pause_container" UnpauseContainer = "docker_unpause_container" RemoveContainer = "docker_remove_container" AttachContainer = "docker_attach_container" ExecContainer = "docker_exec_container" )
Control IDs used by the docker integration.
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.
const ( ImageID = "docker_image_id" ImageName = "docker_image_name" ImageLabelPrefix = "docker_image_label_" OverlayPeerPrefix = "docker_peer_" )
Keys for use in Node
const ( ContainerID = "docker_container_id" Domain = "domain" // TODO this is ambiguous, be more specific Name = "name" // TODO this is ambiguous, be more specific )
Node metadata keys.
Variables ¶
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...
var ( DialStub = net.Dial NewClientConnStub = newClientConn )
Exported for testing
var ( NewDockerClientStub = newDockerClient NewContainerStub = NewContainer )
Vars exported for testing.
var ( ContainerMetadataTemplates = report.MetadataTemplates{ ContainerID: {ID: ContainerID, Label: "ID", From: report.FromLatest, Truncate: 12, Priority: 1}, ContainerStateHuman: {ID: ContainerStateHuman, Label: "State", From: report.FromLatest, Priority: 2}, ContainerCommand: {ID: ContainerCommand, Label: "Command", From: report.FromLatest, Priority: 3}, ImageID: {ID: ImageID, Label: "Image ID", From: report.FromLatest, Truncate: 12, Priority: 11}, ContainerUptime: {ID: ContainerUptime, Label: "Uptime", From: report.FromLatest, Priority: 12}, ContainerRestartCount: {ID: ContainerRestartCount, Label: "Restart #", From: report.FromLatest, Priority: 13}, ContainerNetworks: {ID: ContainerNetworks, Label: "Networks", From: report.FromSets, Priority: 14}, ContainerIPs: {ID: ContainerIPs, Label: "IPs", From: report.FromSets, Priority: 15}, ContainerPorts: {ID: ContainerPorts, Label: "Ports", From: report.FromSets, Priority: 16}, ContainerCreated: {ID: ContainerCreated, Label: "Created", From: report.FromLatest, Priority: 17}, } 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{ ImageID: {ID: ImageID, Label: "Image ID", From: report.FromSets, Truncate: 12, Priority: 1}, report.Container: {ID: report.Container, Label: "# Containers", From: report.FromCounters, Datatype: "number", Priority: 2}, } ContainerTableTemplates = report.TableTemplates{ LabelPrefix: {ID: LabelPrefix, Label: "Docker Labels", Prefix: LabelPrefix}, EnvPrefix: {ID: EnvPrefix, Label: "Environment Variables", Prefix: EnvPrefix}, } ContainerImageTableTemplates = report.TableTemplates{ ImageLabelPrefix: {ID: ImageLabelPrefix, Label: "Docker Labels", Prefix: ImageLabelPrefix}, } ContainerControls = []report.Control{ { ID: AttachContainer, Human: "Attach", Icon: "fa-desktop", Rank: 1, }, { ID: ExecContainer, Human: "Exec shell", Icon: "fa-terminal", Rank: 2, }, { ID: StartContainer, Human: "Start", Icon: "fa-play", Rank: 3, }, { ID: RestartContainer, Human: "Restart", Icon: "fa-repeat", Rank: 4, }, { ID: PauseContainer, Human: "Pause", Icon: "fa-pause", Rank: 5, }, { ID: UnpauseContainer, Human: "Unpause", Icon: "fa-play", Rank: 6, }, { ID: StopContainer, Human: "Stop", Icon: "fa-stop", Rank: 7, }, { ID: RemoveContainer, Human: "Remove", Icon: "fa-trash-o", Rank: 8, }, } )
Exposed for testing
var (
NewProcessTreeStub = process.NewTree
)
These vars are exported for testing.
Functions ¶
func ContainerIsStopped ¶ added in v0.14.0
ContainerIsStopped checks if the docker container is in one of our "stopped" states
func ExtractContainerIPs ¶ added in v0.7.0
ExtractContainerIPs returns the list of container IPs given a Node from the Container topology.
func ExtractContainerIPsWithScopes ¶ added in v0.9.0
ExtractContainerIPsWithScopes returns the list of container IPs, prepended with scopes, given a Node from the Container topology.
func ImageNameWithoutVersion ¶ added in v0.15.0
ImageNameWithoutVersion 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) }
Client interface for mocking.
type ClientConn ¶
ClientConn is exported for testing
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() error StopGatheringStats() NetworkMode() (string, bool) NetworkInfo([]net.IP) report.Sets }
Container represents a Docker container
type ContainerUpdateWatcher ¶ added in v0.10.0
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(interval time.Duration, pipes controls.PipeClient, collectStats bool, hostID string) (Registry, error)
NewRegistry returns a usable Registry. Don't forget to Stop it.
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter generate Reports containing Container and ContainerImage topologies
func NewReporter ¶
NewReporter makes a new Reporter
func (*Reporter) ContainerUpdated ¶ added in v0.10.0
ContainerUpdated should be called whenever a container is updated.
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.