history

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 9 Imported by: 0

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
)

Metrics that can be queried.

Variables

This section is empty.

Functions

This section is empty.

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 Point

type Point struct {
	T int64   `json:"t"` // unix millis
	V float64 `json:"v"`
}

Point is a single (timestamp-ms, value) datapoint in a series.

type Sample

type Sample struct {
	ContainerID string
	Time        time.Time
	CPU         float64 // percent
	MemPercent  float64 // percent of limit
	MemBytes    float64 // bytes
}

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)
	Close() error
}

Store persists and queries metric history.

func Open

func Open(ctx context.Context, cfg Config) Store

Open builds the configured store. If Redis is requested but unreachable it logs a warning and falls back to in-memory, so the app always starts.

Jump to

Keyboard shortcuts

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