Documentation
¶
Overview ¶
Package dockerstats turns what Docker reports about a container into the series the stats store keeps. This file is the pure part: no clock, no I/O.
Index ¶
- Constants
- Variables
- func HealthOf(status string) (float64, bool)
- func StateOf(c container.Summary) string
- type Allocation
- type Config
- type DockerSource
- func (d *DockerSource) Close() error
- func (d *DockerSource) Inspect(ctx context.Context, id string) (container.InspectResponse, error)
- func (d *DockerSource) List(ctx context.Context) ([]container.Summary, error)
- func (d *DockerSource) Stats(ctx context.Context, ids []string) map[string]*container.StatsResponse
- type Identity
- type ItemInfo
- type Sampler
- func (s *Sampler) Alerts(id string) ([]stats.Rule, []stats.Event, error)
- func (s *Sampler) Close() error
- func (s *Sampler) Items() ([]ItemInfo, error)
- func (s *Sampler) Notes() []string
- func (s *Sampler) Run(ctx context.Context)
- func (s *Sampler) Series(id string, r stats.Range) (SeriesView, error)
- func (s *Sampler) SetRules(id string, rules []stats.Rule) error
- func (s *Sampler) Tick(ctx context.Context)
- type SeriesView
- type Snapshot
- type Source
Constants ¶
const MaxGapFactor = 3
MaxGapFactor: a previous snapshot older than this many sampling intervals is not a baseline (Docker or the service was away).
Variables ¶
var ( ErrUnknownItem = errors.New("unknown item") )
Functions ¶
Types ¶
type Allocation ¶
type Allocation struct {
CPULimit float64 // cores; 0 = none declared
MemLimit uint64 // bytes; 0 = none declared
}
Allocation is what the container was declared to be allowed to use.
func AllocationOf ¶
func AllocationOf(h *container.HostConfig) Allocation
AllocationOf reads the declared limits of a container.
func (Allocation) CPUCores ¶
func (a Allocation) CPUCores(s *container.StatsResponse) float64
CPUCores is the number of cores the container can use: its limit, else the machine's online cores as Docker reports them.
type Config ¶
type Config struct {
Dir string // /var/lib/casaos/stats/app_management
Source Source
Clock stats.Clock
Interval time.Duration // 5s in production
// Emit must not block; minutes = the rule's window. Called from the sampler
// goroutine or a route goroutine.
Emit func(e stats.Event, who Identity, minutes int)
}
type DockerSource ¶
type DockerSource struct {
// contains filtered or unexported fields
}
DockerSource reads through one client shared for the life of the process.
func NewDockerSource ¶
func NewDockerSource() (*DockerSource, error)
func (*DockerSource) Close ¶
func (d *DockerSource) Close() error
Close releases the client; calling it again does nothing.
func (*DockerSource) Inspect ¶
func (d *DockerSource) Inspect(ctx context.Context, id string) (container.InspectResponse, error)
func (*DockerSource) Stats ¶
func (d *DockerSource) Stats(ctx context.Context, ids []string) map[string]*container.StatsResponse
type Identity ¶
type Identity struct{ ID, Name, Kind, Group, App string }
Identity is the stable identity of a container: it survives re-creation. Kind: "app-container" | "container".
type ItemInfo ¶
type ItemInfo struct {
Identity
State string // running|stopped|paused|crashed|unknown
CPUPercent *float64 // latest user+system, nil if no sample in the last 3 intervals
MemoryUsed *uint64 // working set
MemoryLimit *uint64 // declared limit only
Alerts int
StartedAt *time.Time // inspect State.StartedAt, nil when unknown (container known only from disk)
Detail string // image name, at most 200 characters, "" when unknown
}
type Sampler ¶
type Sampler struct {
// contains filtered or unexported fields
}
func New ¶
New opens the store and the evaluator, wires the evaluator to the store and rebuilds the alert counters of every item on disk.
func (*Sampler) Close ¶
Close waits for a tick in flight, then closes the store; later calls return nil.
func (*Sampler) Run ¶
Run ticks now, then every Interval, until ctx ends. A slow tick delays the next one; ticks never overlap.
func (*Sampler) SetRules ¶
SetRules updates the rules sent for id; the Evaluator's *stats.RuleError on a bad value. Only an item with history takes rules: Prune drops the rules of any other within the hour. nil means the rules are in alerts.json; an error after they were applied means they are only in memory until the next good write.
type SeriesView ¶
type Snapshot ¶
Snapshot is what a sample leaves behind for the next one: when it was read and the cumulative counters rates are computed from.
func Measure ¶
func Measure(prev *Snapshot, s *container.StatsResponse, now time.Time, a Allocation, maxGap time.Duration) (stats.Sample, Snapshot)
Measure turns one Docker answer into a Sample. A rate needs prev to be at most maxGap older, and each counter is judged alone: one that went backwards (container recreated) drops its own series, not the others.
type Source ¶
type Source interface {
List(ctx context.Context) ([]container.Summary, error)
Inspect(ctx context.Context, id string) (container.InspectResponse, error)
// Stats measures the given containers; an id that could not be measured is absent.
Stats(ctx context.Context, ids []string) map[string]*container.StatsResponse
}
Source is where the sampler reads the containers from.