Documentation
¶
Overview ¶
Package diskguard watches free space on the volumes the platform writes to, refuses risky operations before they fill a disk and keeps a reserve file so SQLite can still commit when space runs out.
Index ¶
Constants ¶
const ( EnvLowFreeMB = "APP_DISK_LOW_FREE_MB" EnvCriticalFreeMB = "APP_DISK_CRITICAL_FREE_MB" EnvReserveMB = "APP_DISK_RESERVE_MB" EnvDockerRoot = "APP_DISK_DOCKER_ROOT" )
Env names for the thresholds, in MiB.
const ( VolumeData = "data" VolumeDocker = "docker" )
Volume names.
const ( // Interval is how often Run checks, kept low because a statfs call is cheap. Interval = time.Minute )
Variables ¶
This section is empty.
Functions ¶
func DockerRootFromEnv ¶
DockerRootFromEnv returns the Docker root dir to watch.
func SystemStat ¶
SystemStat is the real statfs reader.
Types ¶
type Guard ¶
type Guard struct {
// Notify receives a plain-text message on a level change to low or critical.
Notify func(ctx context.Context, text string)
// contains filtered or unexported fields
}
Guard reads volumes on demand; Tick keeps the reserve and the alert state current.
func (*Guard) Refuse ¶
Refuse returns a *LowDiskError when a volume op writes to is below the critical floor.
func (*Guard) ReleaseReserve ¶
ReleaseReserve drops the reserve now, for a caller that just saw ENOSPC.
type LowDiskError ¶
LowDiskError is returned when an operation is refused for lack of space.
func (*LowDiskError) Error ¶
func (e *LowDiskError) Error() string
type Status ¶
type Status struct {
Volumes []Volume `json:"volumes"`
Thresholds Thresholds `json:"thresholds"`
Worst Level `json:"worst"`
ReserveBytes int64 `json:"reserve_held_bytes"`
}
Status is a point-in-time reading.
type Thresholds ¶
type Thresholds struct {
LowFree int64 `json:"low_free_bytes"`
CriticalFree int64 `json:"critical_free_bytes"`
Reserve int64 `json:"reserve_bytes"`
}
Thresholds are free-byte floors.
func ThresholdsFromEnv ¶
func ThresholdsFromEnv(lookup func(string) (string, bool)) Thresholds
ThresholdsFromEnv reads the thresholds, falling back to defaults on unset or invalid values.