Documentation
¶
Overview ¶
Package docker discovers and controls the RabbitMQ container(s) running on the local Docker daemon. It is an optional data source: rbtop must keep working (minus the Container view) when Docker is unavailable.
Index ¶
- type Container
- type ContainerClient
- type FakeClient
- func (f *FakeClient) FindRabbitMQContainers(ctx context.Context) ([]Container, error)
- func (f *FakeClient) Logs(ctx context.Context, id string, tailLines int) (io.ReadCloser, error)
- func (f *FakeClient) Restart(ctx context.Context, id string) error
- func (f *FakeClient) Start(ctx context.Context, id string) error
- func (f *FakeClient) Stats(ctx context.Context, id string) (Stats, error)
- func (f *FakeClient) Stop(ctx context.Context, id string) error
- type RealClient
- func (r *RealClient) FindRabbitMQContainers(ctx context.Context) ([]Container, error)
- func (r *RealClient) Logs(ctx context.Context, id string, tailLines int) (io.ReadCloser, error)
- func (r *RealClient) Restart(ctx context.Context, id string) error
- func (r *RealClient) Start(ctx context.Context, id string) error
- func (r *RealClient) Stats(ctx context.Context, id string) (Stats, error)
- func (r *RealClient) Stop(ctx context.Context, id string) error
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container struct {
ID string
Name string
Image string
Status string
// ManagementPort is the host port mapped to the container's
// 15672/tcp (Management API) port, or 0 if that port isn't published
// to the host (e.g. host networking, or a non-standard setup).
ManagementPort int
}
Container is a running Docker container that looks like a RabbitMQ instance (its image name contains "rabbitmq").
type ContainerClient ¶
type ContainerClient interface {
// FindRabbitMQContainers lists running containers whose image name
// contains "rabbitmq".
FindRabbitMQContainers(ctx context.Context) ([]Container, error)
Stats(ctx context.Context, id string) (Stats, error)
Start(ctx context.Context, id string) error
Stop(ctx context.Context, id string) error
Restart(ctx context.Context, id string) error
// Logs returns a stream of the container's logs; the caller must close it.
Logs(ctx context.Context, id string, tailLines int) (io.ReadCloser, error)
}
ContainerClient is the subset of Docker operations rbtop needs. It is an interface so tests can substitute a fake instead of requiring a real Docker daemon.
type FakeClient ¶
type FakeClient struct {
Containers []Container
StatsByID map[string]Stats
LogsByID map[string]string
// Calls records every mutating call made, in order, as
// "action:containerID" (e.g. "start:abc123"), so tests can assert on
// what the code under test actually did.
Calls []string
// ErrByAction, if set for an action name ("start", "stop", "restart"),
// makes that action return the given error instead of succeeding.
ErrByAction map[string]error
}
FakeClient is an in-memory ContainerClient for tests, avoiding the need for a real Docker daemon.
func (*FakeClient) FindRabbitMQContainers ¶
func (f *FakeClient) FindRabbitMQContainers(ctx context.Context) ([]Container, error)
func (*FakeClient) Logs ¶
func (f *FakeClient) Logs(ctx context.Context, id string, tailLines int) (io.ReadCloser, error)
type RealClient ¶
type RealClient struct {
// contains filtered or unexported fields
}
RealClient is a ContainerClient backed by the actual Docker daemon, reached over the standard Docker socket/env configuration.
func NewRealClient ¶
func NewRealClient() (*RealClient, error)
NewRealClient connects to the Docker daemon. It honors DOCKER_HOST like the Docker CLI, but if that's unset it also resolves the CLI's active context (~/.docker/config.json's currentContext) — otherwise, on setups like Docker Desktop where the daemon isn't at the default /var/run/docker.sock, rbtop would silently see zero containers even though `docker ps` works fine.
func (*RealClient) FindRabbitMQContainers ¶
func (r *RealClient) FindRabbitMQContainers(ctx context.Context) ([]Container, error)
FindRabbitMQContainers lists running containers whose image name contains "rabbitmq".
func (*RealClient) Logs ¶
func (r *RealClient) Logs(ctx context.Context, id string, tailLines int) (io.ReadCloser, error)
Logs returns the last tailLines lines of the container's combined stdout/stderr log stream.
func (*RealClient) Restart ¶
func (r *RealClient) Restart(ctx context.Context, id string) error
Restart restarts the container using Docker's default timeout.
func (*RealClient) Start ¶
func (r *RealClient) Start(ctx context.Context, id string) error
Start starts the container.