Documentation ¶
Index ¶
- Constants
- func HasErrorCode(err error, code int) bool
- func NewDummyAppConfig() *config.AppConfig
- func NewDummyLog() *logrus.Entry
- func WrapError(err error) error
- type CommandObject
- type ComplexError
- type Container
- func (c *Container) Attach() (*exec.Cmd, error)
- func (c *Container) DetailsLoaded() bool
- func (c *Container) GetLastStats() (*RecordedStats, bool)
- func (c *Container) Inspect() (dockerTypes.ContainerJSON, error)
- func (c *Container) Pause() error
- func (c *Container) Remove(options container.RemoveOptions) error
- func (c *Container) RenderTop(ctx context.Context) (string, error)
- func (c *Container) Restart() error
- func (c *Container) Stop() error
- func (c *Container) Top(ctx context.Context) (container.ContainerTopOKBody, error)
- func (c *Container) Unpause() error
- type ContainerStats
- type DerivedStats
- type DockerCommand
- func (c *DockerCommand) Close() error
- func (c *DockerCommand) CreateClientStatMonitor(container *Container)
- func (c *DockerCommand) DockerComposeConfig() string
- func (c *DockerCommand) GetContainers(existingContainers []*Container) ([]*Container, error)
- func (c *DockerCommand) GetServices() ([]*Service, error)
- func (c *DockerCommand) NewCommandObject(obj CommandObject) CommandObject
- func (c *DockerCommand) PruneContainers() error
- func (c *DockerCommand) PruneImages() error
- func (c *DockerCommand) PruneNetworks() error
- func (c *DockerCommand) PruneVolumes() error
- func (c *DockerCommand) RefreshContainerDetails(containers []*Container) error
- func (c *DockerCommand) RefreshContainersAndServices(currentServices []*Service, currentContainers []*Container) ([]*Container, []*Service, error)
- func (c *DockerCommand) RefreshImages() ([]*Image, error)
- func (c *DockerCommand) RefreshNetworks() ([]*Network, error)
- func (c *DockerCommand) RefreshVolumes() ([]*Volume, error)
- func (c *DockerCommand) SetContainerDetails(containers []*Container)
- func (c *DockerCommand) ViewAllLogs() (*exec.Cmd, error)
- type Image
- type LimitedDockerCommand
- type Network
- type OSCommand
- func (c *OSCommand) AppendLineToFile(filename, line string) error
- func (c *OSCommand) CreateTempFile(filename, content string) (string, error)
- func (c *OSCommand) EditFile(filename string) (*exec.Cmd, error)
- func (c *OSCommand) ExecutableFromString(commandStr string) *exec.Cmd
- func (c *OSCommand) ExecutableFromStringContext(ctx context.Context, commandStr string) *exec.Cmd
- func (c *OSCommand) FileExists(path string) (bool, error)
- func (c *OSCommand) FileType(path string) string
- func (c *OSCommand) GetLazydockerPath() string
- func (c *OSCommand) Kill(cmd *exec.Cmd) error
- func (c *OSCommand) NewCmd(cmdName string, commandArgs ...string) *exec.Cmd
- func (c *OSCommand) NewCommandStringWithShell(commandStr string) string
- func (c *OSCommand) OpenFile(filename string) error
- func (c *OSCommand) OpenLink(link string) error
- func (c *OSCommand) PipeCommands(commandStrings ...string) error
- func (c *OSCommand) PrepareForChildren(cmd *exec.Cmd)
- func (c *OSCommand) Quote(message string) string
- func (c *OSCommand) Remove(filename string) error
- func (c *OSCommand) RunCommand(command string) error
- func (c *OSCommand) RunCommandWithOutput(command string) (string, error)
- func (c *OSCommand) RunCommandWithOutputContext(ctx context.Context, command string) (string, error)
- func (c *OSCommand) RunCustomCommand(command string) *exec.Cmd
- func (c *OSCommand) RunExecutable(cmd *exec.Cmd) error
- func (c *OSCommand) RunExecutableWithOutput(cmd *exec.Cmd) (string, error)
- func (c *OSCommand) RunPreparedCommand(cmd *exec.Cmd) error
- func (c *OSCommand) SetCommand(cmd func(string, ...string) *exec.Cmd)
- func (c *OSCommand) Unquote(message string) string
- type Platform
- type Project
- type RecordedStats
- type Service
- func (s *Service) Attach() (*exec.Cmd, error)
- func (s *Service) Remove(options container.RemoveOptions) error
- func (s *Service) RenderTop(ctx context.Context) (string, error)
- func (s *Service) Restart() error
- func (s *Service) Start() error
- func (s *Service) Stop() error
- func (s *Service) Up() error
- func (s *Service) ViewLogs() (*exec.Cmd, error)
- type Volume
Constants ¶
const (
APIVersion = "1.25"
)
const ( // MustStopContainer tells us that we must stop the container before removing it MustStopContainer = iota )
Variables ¶
This section is empty.
Functions ¶
func NewDummyAppConfig ¶
NewDummyAppConfig creates a new dummy AppConfig for testing
Types ¶
type CommandObject ¶
type CommandObject struct { DockerCompose string Service *Service Container *Container Image *Image Volume *Volume Network *Network }
CommandObject is what we pass to our template resolvers when we are running a custom command. We do not guarantee that all fields will be populated: just the ones that make sense for the current context
type ComplexError ¶
ComplexError an error which carries a code so that calling code has an easier job to do adapted from https://medium.com/yakka/better-go-error-handling-with-xerrors-1987650e0c79
func (ComplexError) Error ¶
func (ce ComplexError) Error() string
func (ComplexError) Format ¶
func (ce ComplexError) Format(f fmt.State, c rune)
Format is a function
func (ComplexError) FormatError ¶
func (ce ComplexError) FormatError(p xerrors.Printer) error
FormatError is a function
type Container ¶
type Container struct { Name string ServiceName string ContainerNumber string // might make this an int in the future if need be // OneOff tells us if the container is just a job container or is actually bound to the service OneOff bool ProjectName string ID string Container dockerTypes.Container Client *client.Client OSCommand *OSCommand Log *logrus.Entry StatHistory []*RecordedStats Details dockerTypes.ContainerJSON MonitoringStats bool DockerCommand LimitedDockerCommand Tr *i18n.TranslationSet StatsMutex deadlock.Mutex }
Container : A docker Container
func (*Container) DetailsLoaded ¶ added in v0.2.1
DetailsLoaded tells us whether we have yet loaded the details for a container. Sometimes it takes some time for a container to have its details loaded after it starts.
func (*Container) GetLastStats ¶ added in v0.20.0
func (c *Container) GetLastStats() (*RecordedStats, bool)
func (*Container) Inspect ¶
func (c *Container) Inspect() (dockerTypes.ContainerJSON, error)
Inspect returns details about the container
func (*Container) Remove ¶
func (c *Container) Remove(options container.RemoveOptions) error
Remove removes the container
type ContainerStats ¶
type ContainerStats struct { Read time.Time `json:"read"` Preread time.Time `json:"preread"` PidsStats struct { Current int `json:"current"` } `json:"pids_stats"` BlkioStats struct { IoServiceBytesRecursive []struct { Major int `json:"major"` Minor int `json:"minor"` Op string `json:"op"` Value int `json:"value"` } `json:"io_service_bytes_recursive"` IoServicedRecursive []struct { Major int `json:"major"` Minor int `json:"minor"` Op string `json:"op"` Value int `json:"value"` } `json:"io_serviced_recursive"` IoQueueRecursive []interface{} `json:"io_queue_recursive"` IoServiceTimeRecursive []interface{} `json:"io_service_time_recursive"` IoWaitTimeRecursive []interface{} `json:"io_wait_time_recursive"` IoMergedRecursive []interface{} `json:"io_merged_recursive"` IoTimeRecursive []interface{} `json:"io_time_recursive"` SectorsRecursive []interface{} `json:"sectors_recursive"` } `json:"blkio_stats"` NumProcs int `json:"num_procs"` StorageStats struct{} `json:"storage_stats"` CPUStats struct { CPUUsage struct { TotalUsage int64 `json:"total_usage"` PercpuUsage []int64 `json:"percpu_usage"` UsageInKernelmode int64 `json:"usage_in_kernelmode"` UsageInUsermode int64 `json:"usage_in_usermode"` } `json:"cpu_usage"` SystemCPUUsage int64 `json:"system_cpu_usage"` OnlineCpus int `json:"online_cpus"` ThrottlingData struct { Periods int `json:"periods"` ThrottledPeriods int `json:"throttled_periods"` ThrottledTime int `json:"throttled_time"` } `json:"throttling_data"` } `json:"cpu_stats"` PrecpuStats struct { CPUUsage struct { TotalUsage int64 `json:"total_usage"` PercpuUsage []int64 `json:"percpu_usage"` UsageInKernelmode int64 `json:"usage_in_kernelmode"` UsageInUsermode int64 `json:"usage_in_usermode"` } `json:"cpu_usage"` SystemCPUUsage int64 `json:"system_cpu_usage"` OnlineCpus int `json:"online_cpus"` ThrottlingData struct { Periods int `json:"periods"` ThrottledPeriods int `json:"throttled_periods"` ThrottledTime int `json:"throttled_time"` } `json:"throttling_data"` } `json:"precpu_stats"` MemoryStats struct { Usage int `json:"usage"` MaxUsage int `json:"max_usage"` Stats struct { ActiveAnon int `json:"active_anon"` ActiveFile int `json:"active_file"` Cache int `json:"cache"` Dirty int `json:"dirty"` HierarchicalMemoryLimit int64 `json:"hierarchical_memory_limit"` HierarchicalMemswLimit int64 `json:"hierarchical_memsw_limit"` InactiveAnon int `json:"inactive_anon"` InactiveFile int `json:"inactive_file"` MappedFile int `json:"mapped_file"` Pgfault int `json:"pgfault"` Pgmajfault int `json:"pgmajfault"` Pgpgin int `json:"pgpgin"` Pgpgout int `json:"pgpgout"` Rss int `json:"rss"` RssHuge int `json:"rss_huge"` TotalActiveAnon int `json:"total_active_anon"` TotalActiveFile int `json:"total_active_file"` TotalCache int `json:"total_cache"` TotalDirty int `json:"total_dirty"` TotalInactiveAnon int `json:"total_inactive_anon"` TotalInactiveFile int `json:"total_inactive_file"` TotalMappedFile int `json:"total_mapped_file"` TotalPgfault int `json:"total_pgfault"` TotalPgmajfault int `json:"total_pgmajfault"` TotalPgpgin int `json:"total_pgpgin"` TotalPgpgout int `json:"total_pgpgout"` TotalRss int `json:"total_rss"` TotalRssHuge int `json:"total_rss_huge"` TotalUnevictable int `json:"total_unevictable"` TotalWriteback int `json:"total_writeback"` Unevictable int `json:"unevictable"` Writeback int `json:"writeback"` } `json:"stats"` Limit int64 `json:"limit"` } `json:"memory_stats"` Name string `json:"name"` ID string `json:"id"` Networks struct { Eth0 struct { RxBytes int `json:"rx_bytes"` RxPackets int `json:"rx_packets"` RxErrors int `json:"rx_errors"` RxDropped int `json:"rx_dropped"` TxBytes int `json:"tx_bytes"` TxPackets int `json:"tx_packets"` TxErrors int `json:"tx_errors"` TxDropped int `json:"tx_dropped"` } `json:"eth0"` } `json:"networks"` }
ContainerStats autogenerated at https://mholt.github.io/json-to-go/
func (*ContainerStats) CalculateContainerCPUPercentage ¶
func (s *ContainerStats) CalculateContainerCPUPercentage() float64
CalculateContainerCPUPercentage calculates the cpu usage of the container as a percent of total CPU usage to calculate CPU usage, we take the increase in CPU time from the container since the last poll, divide that by the total increase in CPU time since the last poll, times by the number of cores, and times by 100 to get a percentage I'm not entirely sure why we need to multiply by the number of cores, but the numbers work
func (*ContainerStats) CalculateContainerMemoryUsage ¶
func (s *ContainerStats) CalculateContainerMemoryUsage() float64
CalculateContainerMemoryUsage calculates the memory usage of the container as a percent of total available memory
type DerivedStats ¶
DerivedStats contains some useful stats that we've calculated based on the raw container stats that we got back from docker
type DockerCommand ¶
type DockerCommand struct { Log *logrus.Entry OSCommand *OSCommand Tr *i18n.TranslationSet Config *config.AppConfig Client *client.Client InDockerComposeProject bool ErrorChan chan error ContainerMutex deadlock.Mutex ServiceMutex deadlock.Mutex Closers []io.Closer }
DockerCommand is our main docker interface
func NewDockerCommand ¶
func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.TranslationSet, config *config.AppConfig, errorChan chan error) (*DockerCommand, error)
NewDockerCommand it runs docker commands
func NewDummyDockerCommand ¶
func NewDummyDockerCommand() *DockerCommand
NewDummyDockerCommand creates a new dummy DockerCommand for testing
func NewDummyDockerCommandWithOSCommand ¶
func NewDummyDockerCommandWithOSCommand(osCommand *OSCommand) *DockerCommand
NewDummyDockerCommandWithOSCommand creates a new dummy DockerCommand for testing
func (*DockerCommand) Close ¶ added in v0.17.1
func (c *DockerCommand) Close() error
func (*DockerCommand) CreateClientStatMonitor ¶ added in v0.20.0
func (c *DockerCommand) CreateClientStatMonitor(container *Container)
func (*DockerCommand) DockerComposeConfig ¶
func (c *DockerCommand) DockerComposeConfig() string
DockerComposeConfig returns the result of 'docker-compose config'
func (*DockerCommand) GetContainers ¶
func (c *DockerCommand) GetContainers(existingContainers []*Container) ([]*Container, error)
GetContainers gets the docker containers
func (*DockerCommand) GetServices ¶
func (c *DockerCommand) GetServices() ([]*Service, error)
GetServices gets services
func (*DockerCommand) NewCommandObject ¶
func (c *DockerCommand) NewCommandObject(obj CommandObject) CommandObject
NewCommandObject takes a command object and returns a default command object with the passed command object merged in
func (*DockerCommand) PruneContainers ¶
func (c *DockerCommand) PruneContainers() error
PruneContainers prunes containers
func (*DockerCommand) PruneImages ¶
func (c *DockerCommand) PruneImages() error
PruneImages prunes images
func (*DockerCommand) PruneNetworks ¶ added in v0.21.0
func (c *DockerCommand) PruneNetworks() error
PruneNetworks prunes networks
func (*DockerCommand) PruneVolumes ¶
func (c *DockerCommand) PruneVolumes() error
PruneVolumes prunes volumes
func (*DockerCommand) RefreshContainerDetails ¶ added in v0.23.2
func (c *DockerCommand) RefreshContainerDetails(containers []*Container) error
func (*DockerCommand) RefreshContainersAndServices ¶
func (*DockerCommand) RefreshImages ¶ added in v0.2.1
func (c *DockerCommand) RefreshImages() ([]*Image, error)
RefreshImages returns a slice of docker images
func (*DockerCommand) RefreshNetworks ¶ added in v0.21.0
func (c *DockerCommand) RefreshNetworks() ([]*Network, error)
RefreshNetworks gets the networks and stores them
func (*DockerCommand) RefreshVolumes ¶
func (c *DockerCommand) RefreshVolumes() ([]*Volume, error)
RefreshVolumes gets the volumes and stores them
func (*DockerCommand) SetContainerDetails ¶ added in v0.23.2
func (c *DockerCommand) SetContainerDetails(containers []*Container)
Attaches the details returned from docker inspect to each of the containers this contains a bit more info than what you get from the go-docker client
func (*DockerCommand) ViewAllLogs ¶
func (c *DockerCommand) ViewAllLogs() (*exec.Cmd, error)
ViewAllLogs attaches to a subprocess viewing all the logs from docker-compose
type Image ¶
type Image struct { Name string Tag string ID string Image image.Summary Client *client.Client OSCommand *OSCommand Log *logrus.Entry DockerCommand LimitedDockerCommand }
Image : A docker Image
func (*Image) Remove ¶
func (i *Image) Remove(options image.RemoveOptions) error
Remove removes the image
func (*Image) RenderHistory ¶
RenderHistory renders the history of the image
type LimitedDockerCommand ¶
type LimitedDockerCommand interface {
NewCommandObject(CommandObject) CommandObject
}
LimitedDockerCommand is a stripped-down DockerCommand with just the methods the container/service/image might need
type Network ¶ added in v0.21.0
type Network struct { Name string Network network.Inspect Client *client.Client OSCommand *OSCommand Log *logrus.Entry DockerCommand LimitedDockerCommand }
Network : A docker Network
type OSCommand ¶
type OSCommand struct { Log *logrus.Entry Platform *Platform Config *config.AppConfig // contains filtered or unexported fields }
OSCommand holds all the os commands
func NewDummyOSCommand ¶
func NewDummyOSCommand() *OSCommand
NewDummyOSCommand creates a new dummy OSCommand for testing
func NewOSCommand ¶
NewOSCommand os command runner
func (*OSCommand) AppendLineToFile ¶
AppendLineToFile adds a new line in file
func (*OSCommand) CreateTempFile ¶
CreateTempFile writes a string to a new temp file and returns the file's name
func (*OSCommand) EditFile ¶
EditFile opens a file in a subprocess using whatever editor is available, falling back to core.editor, VISUAL, EDITOR, then vi
func (*OSCommand) ExecutableFromString ¶
ExecutableFromString takes a string like `docker ps -a` and returns an executable command for it
func (*OSCommand) ExecutableFromStringContext ¶ added in v0.20.0
Same as ExecutableFromString but cancellable via a context
func (*OSCommand) FileExists ¶
FileExists checks whether a file exists at the specified path
func (*OSCommand) GetLazydockerPath ¶
GetLazydockerPath returns the path of the currently executed file
func (*OSCommand) Kill ¶
Kill kills a process. If the process has Setpgid == true, then we have anticipated that it might spawn its own child processes, so we've given it a process group ID (PGID) equal to its process id (PID) and given its child processes will inherit the PGID, we can kill that group, rather than killing the process itself.
func (*OSCommand) NewCommandStringWithShell ¶ added in v0.21.0
func (*OSCommand) PipeCommands ¶
PipeCommands runs a heap of commands and pipes their inputs/outputs together like A | B | C
func (*OSCommand) PrepareForChildren ¶
PrepareForChildren sets Setpgid to true on the cmd, so that when we run it as a subprocess, we can kill its group rather than the process itself. This is because some commands, like `docker-compose logs` spawn multiple children processes, and killing the parent process isn't sufficient for killing those child processes. We set the group id here, and then in subprocess.go we check if the group id is set and if so, we kill the whole group rather than just the one process.
func (*OSCommand) RunCommand ¶
RunCommand runs a command and just returns the error
func (*OSCommand) RunCommandWithOutput ¶
RunCommandWithOutput wrapper around commands returning their output and error
func (*OSCommand) RunCommandWithOutputContext ¶ added in v0.20.0
func (c *OSCommand) RunCommandWithOutputContext(ctx context.Context, command string) (string, error)
RunCommandWithOutput wrapper around commands returning their output and error
func (*OSCommand) RunCustomCommand ¶
RunCustomCommand returns the pointer to a custom command
func (*OSCommand) RunExecutable ¶
RunExecutable runs an executable file and returns an error if there was one
func (*OSCommand) RunExecutableWithOutput ¶
RunExecutableWithOutput runs an executable file and returns its output
func (*OSCommand) RunPreparedCommand ¶
RunPreparedCommand takes a pointer to an exec.Cmd and runs it this is useful if you need to give your command some environment variables before running it
func (*OSCommand) SetCommand ¶
SetCommand sets the command function used by the struct. To be used for testing only
type Platform ¶
type Platform struct {
// contains filtered or unexported fields
}
Platform stores the os state
type RecordedStats ¶
type RecordedStats struct { ClientStats ContainerStats DerivedStats DerivedStats RecordedAt time.Time }
RecordedStats contains both the container stats we've received from docker, and our own derived stats from those container stats. When configuring a graph, you're basically specifying the path of a value in this struct
type Service ¶
type Service struct { Name string ID string OSCommand *OSCommand Log *logrus.Entry Container *Container DockerCommand LimitedDockerCommand }
Service : A docker Service
func (*Service) Remove ¶
func (s *Service) Remove(options container.RemoveOptions) error
Remove removes the service's containers