dockerstats

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func NewClient(socketPath string, nameOverrides map[string]string) (*Client, error)

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

func (c *Client) ContainerEnv(ctx context.Context, containerName string) (map[string]string, error)

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

func (c *Client) ContainerStats(ctx context.Context, containerName string) (*Stats, error)

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

func (c *Client) ContainerStatsByService(ctx context.Context, serviceName string) (*Stats, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL