Documentation
¶
Index ¶
- func Monitor(ctx context.Context) error
- type ContainerConfig
- type ContainerStatsSummary
- type DockerManager
- func (dm *DockerManager) Create(config ContainerConfig) (string, error)
- func (dm *DockerManager) EnsureImage(imageName string) error
- func (dm *DockerManager) GetLogs(containerID string) (string, error)
- func (dm *DockerManager) GetStats(containerID string) (string, error)
- func (dm *DockerManager) GetStatsStreamed(containerID string, startTime time.Time, resultCh chan<- ContainerStatsSummary, ...)
- func (dm *DockerManager) IsRunning(containerID string) (bool, error)
- func (dm *DockerManager) Ping() error
- func (dm *DockerManager) Remove(containerID string) error
- func (dm *DockerManager) Start(containerID string) error
- func (dm *DockerManager) Stop(containerID string, timeout int) error
- func (dm *DockerManager) Wait(containerID string) (container.WaitResponse, error)
- type Manager
- type StatsRecord
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ContainerConfig ¶
ContainerConfig struct with Image, Cmd and Tty fields
type ContainerStatsSummary ¶ added in v1.3.2
type ContainerStatsSummary struct {
Duration time.Duration // Total time the container ran
LastMemUsage uint64 // Memory usage in the last stats frame (bytes)
PeakMemUsage uint64 // Peak memory usage over the container’s lifetime (bytes)
LastCPUPercent float64 // CPU percentage in the last stats frame
}
ContainerStatsSummary holds the aggregated stats we want at container exit.
type DockerManager ¶
type DockerManager struct {
// contains filtered or unexported fields
}
DockerManager struct with cli field
func (*DockerManager) Create ¶
func (dm *DockerManager) Create(config ContainerConfig) (string, error)
Function to create a container
func (*DockerManager) EnsureImage ¶ added in v1.2.0
func (dm *DockerManager) EnsureImage(imageName string) error
ensureImage checks if there is an image of the container if not it pulls it.
func (*DockerManager) GetLogs ¶
func (dm *DockerManager) GetLogs(containerID string) (string, error)
Function to get logs from a container
func (*DockerManager) GetStats ¶ added in v0.11.0
func (dm *DockerManager) GetStats(containerID string) (string, error)
Function to get stats from docker container and format them
func (*DockerManager) GetStatsStreamed ¶ added in v1.3.2
func (dm *DockerManager) GetStatsStreamed( containerID string, startTime time.Time, resultCh chan<- ContainerStatsSummary, errCh chan<- error, )
func (*DockerManager) IsRunning ¶ added in v0.5.1
func (dm *DockerManager) IsRunning(containerID string) (bool, error)
Function to check if a container is running
func (*DockerManager) Ping ¶ added in v1.2.2
func (dm *DockerManager) Ping() error
func (*DockerManager) Remove ¶
func (dm *DockerManager) Remove(containerID string) error
Function to remove a container
func (*DockerManager) Start ¶
func (dm *DockerManager) Start(containerID string) error
Function to start a container
func (*DockerManager) Stop ¶
func (dm *DockerManager) Stop(containerID string, timeout int) error
Function to stop a container
func (*DockerManager) Wait ¶ added in v0.4.0
func (dm *DockerManager) Wait(containerID string) (container.WaitResponse, error)
Function to wait for a container
type Manager ¶
type Manager interface {
Create(config ContainerConfig) (string, error)
Start(id string) error
Stop(id string, timeout int) error
Remove(id string) error
GetLogs(id string) (string, error)
Wait(id string) (container.WaitResponse, error)
IsRunning(id string) (bool, error)
GetStats(containerID string) (string, error)
GetStatsStreamed(
containerID string,
startTime time.Time,
resultCh chan<- ContainerStatsSummary,
errCh chan<- error,
)
EnsureImage(image string) error
Ping() error
}
Manager interface with methods to manage containers
type StatsRecord ¶ added in v1.4.3
type StatsRecord struct {
ID string `json:"id"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Duration time.Duration `json:"duration"`
CPUUsageNs uint64 `json:"cpu_usage_ns"`
MemUsageBytes uint64 `json:"mem_usage_bytes"`
MemMaxBytes uint64 `json:"mem_max_bytes"`
}
StatsRecord holds exactly the fields we need for one container run.
func CaptureMetrics ¶ added in v1.4.3
func CaptureMetrics(containerID string, start, end time.Time) (*StatsRecord, error)
CaptureMetrics reads from /sys/fs/cgroup (v1) for CPU and memory usage. Adjust the paths if you are on cgroup v2 or a non‐Docker cgroup hierarchy.