Documentation
¶
Overview ¶
Package dockerstats provides a thin client over the Docker Engine API for reading per-container resource statistics. Used by Pulse's dashboard to surface CPU / memory / network / block-IO for each registered service.
Implemented directly against the Engine API over a Unix socket rather than pulling in the full docker/docker SDK, which would add tens of MB of transitive dependencies. The three endpoints we need are stable and well-documented.
Disabled mode: if the socket path is empty, NewClient returns (nil, nil) — every consumer must check for nil before calling. This is the graceful-degradation path: if the operator hasn't opted in by mounting /var/run/docker.sock and setting PULSE_DOCKER_SOCKET, Pulse still works, container fields just render as null in the dashboard.
Security: even a read-only docker socket grants effective root on the host. The env-gate is intentional — operators must opt in.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDisabled = errors.New("dockerstats: disabled (no socket configured)")
ErrDisabled is returned when a method is called on a nil/disabled client.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the Docker Engine API over a Unix socket. The zero value is invalid; use NewClient.
func NewClient ¶
NewClient returns a Docker Engine API client backed by the given Unix socket. If socketPath is empty, returns (nil, nil) — callers should treat nil as "disabled" and skip container stats. Any other error indicates a real problem (socket unreachable, permission denied, etc.).
func (*Client) ContainerEnv ¶
ContainerEnv returns the effective environment of a container as a map. Used by the dashboard to pull metadata Gluetun's control server doesn't expose (e.g. VPN_SERVICE_PROVIDER). Returns ErrDisabled when the client is nil; an empty (non-nil) map when the container exists but has no env; an error on lookup failure.
func (*Client) ContainerStats ¶
ContainerStats fetches a snapshot of stats for the given container name. The Docker API's `stats?stream=false` endpoint returns cumulative counters plus a precpu snapshot — one HTTP call gives us everything for CPU%. Network rates are derived from the local cache against a previous snapshot.
func (*Client) ContainerStatsByService ¶
ContainerStatsByService maps a logical service name (as registered with Pulse) to a container name and fetches its stats. The mapping rule is lowercase service name, with PULSE_CONTAINER_NAMES overrides taking precedence (e.g. "Haul" → "haul-prod" when overridden).
type Stats ¶
type Stats struct {
Name string `json:"name"`
CPUPercent float64 `json:"cpu_percent"`
MemUsageBytes uint64 `json:"mem_usage_bytes"`
MemLimitBytes uint64 `json:"mem_limit_bytes"`
NetRxBytes uint64 `json:"net_rx_bytes"`
NetTxBytes uint64 `json:"net_tx_bytes"`
NetRxRateBps float64 `json:"net_rx_rate_bps"`
NetTxRateBps float64 `json:"net_tx_rate_bps"`
BlockReadBytes uint64 `json:"block_read_bytes"`
BlockWriteBytes uint64 `json:"block_write_bytes"`
PIDs uint64 `json:"pids"`
HealthStatus string `json:"health_status"` // "healthy", "starting", "unhealthy", "" (no healthcheck)
}
Stats is the subset of Docker container stats Pulse cares about. Cumulative counters are returned alongside derived per-second rates.