Documentation
¶
Overview ¶
Package history stores a rolling window of container resource metrics for charting. It has two interchangeable backends selected at runtime:
- in-memory ring (default, zero-config, lost on restart)
- Redis (set DC_REDIS_ADDR) — survives restarts and can be shared
The backend is chosen by Config; everything else in the app talks to the Store interface only.
Index ¶
Constants ¶
View Source
const ( MetricCPU = "cpu" MetricMem = "mem" // percent MetricMemBytes = "membytes" // bytes // Network series are CUMULATIVE byte counters, not rates. A rate depends on // the sampling interval, so storing one would bake that interval into the // history and make every stored point wrong the day the interval changes. // Readers derive rates from consecutive points instead — and can see a // counter reset for what it is, which a stored rate would have hidden. MetricNetRx = "netrx" // cumulative bytes received MetricNetTx = "nettx" // cumulative bytes sent // Drops and errors are stored as RX+TX combined rather than as four series. // They are near-zero almost always, so four series would double the write // volume to store zeros; and what an operator acts on is "this container // started losing packets", not the direction. The live view keeps the split. MetricNetDrops = "netdrops" // cumulative dropped packets, rx+tx MetricNetErrors = "neterrors" // cumulative interface errors, rx+tx )
Metrics that can be queried.
Variables ¶
This section is empty.
Functions ¶
func AllMetrics ¶ added in v1.6.0
func AllMetrics() []string
AllMetrics reports the series recorded for every sample. Exported so callers that gate on metric names can be checked against what is actually stored, rather than drifting from it silently.
Types ¶
type Config ¶
type Config struct {
RedisAddr string // empty → in-memory
RedisPassword string
RedisDB int
Retention time.Duration // how long to keep points
}
Config selects and configures the backend.
type Sample ¶
type Sample struct {
ContainerID string
// HostID is the Docker host the container runs on. Recorded so a series can
// be authorised against the caller's host scope: a container id is the only
// key here, and knowing one is otherwise enough to read its CPU/memory
// history from a host the caller was scoped away from.
HostID int64
Time time.Time
CPU float64 // percent
MemPercent float64 // percent of limit
MemBytes float64 // bytes
NetRx float64 // cumulative bytes received, summed across interfaces
NetTx float64 // cumulative bytes sent
NetDrops float64 // cumulative dropped packets, rx+tx
NetErrors float64 // cumulative interface errors, rx+tx
}
Sample is one moment's resource reading for a container.
type Store ¶
type Store interface {
Record(ctx context.Context, samples []Sample) error
Query(ctx context.Context, containerID, metric string, since time.Time) ([]Point, error)
// HostFor reports which host a container's samples were recorded from.
// ok=false means nothing has ever been recorded for that id, which callers
// must treat as "unknown", not as the local daemon.
HostFor(ctx context.Context, containerID string) (hostID int64, ok bool, err error)
Close() error
}
Store persists and queries metric history.
Click to show internal directories.
Click to hide internal directories.