storageusage

package
v0.252.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 9 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 storageusage measures what the database and the blob store hold, groups it for the operator, and fits a line through the daily samples to say when a measured disk fills.

Index

Constants

View Source
const (
	DiskDataDirectory = "dataDirectory"
	DiskFileDirectory = "fileDirectory"
	DiskObjectStore   = "objectStore"
)

The labels of the disks, as keys: the interface names them in the operator's language.

View Source
const (
	// ProjectionWindowDays is how far back the fit looks: the last thirty
	// days of daily samples, or fewer when there is less history.
	ProjectionWindowDays = 30

	// MinimumProjectionSamples is how few daily samples a line is not fitted
	// through: two points always make a line, and that line says nothing.
	MinimumProjectionSamples = 3

	// The days of room left at which an operator is warned about a disk.
	FirstWarningDays  = 30
	SecondWarningDays = 7
)
View Source
const SampleRetention = 400 * 24 * time.Hour

SampleRetention is how long the daily samples are kept: a year of trend, and a margin for a year view that starts a few weeks back.

Variables

Areas is every area, in the order a breakdown lists them.

Functions

func DescribeBytes

func DescribeBytes(sizeBytes int64) string

DescribeBytes writes a size the way an operator reads a disk: 1024-based units, one decimal from a megabyte up.

func FileDirectory

func FileDirectory(configuration *config.Configuration) string

FileDirectory is the directory the blob store keeps its files in, or empty when it keeps none on this machine.

func IsObjectStoreOnly

func IsObjectStoreOnly(configuration *config.Configuration) bool

IsObjectStoreOnly is whether the files are in an object store and none are kept on this machine, so their growth does not fill any disk the server can measure.

func ListedTables

func ListedTables() []string

ListedTables is every table the map names, sorted.

func Samples

func Samples(snapshot *Snapshot, disks []Disk, now time.Time) []models.StorageUsageSample

Samples is what a day's measurement writes: the database and each area, each kind of file, and each measured disk.

func TablesOf

func TablesOf(area Area) []string

TablesOf is the tables listed under an area.

func WarningDaysFor

func WarningDaysFor(daysUntilFull float64) int

WarningDaysFor is the warning a disk that fills in daysUntilFull is due: seven, thirty, or zero for none.

Types

type Area

type Area string

Area is what a table is for, as an operator reads a breakdown of the database.

const (
	AreaMail          Area = "mail"
	AreaMemory        Area = "memory"
	AreaConversations Area = "conversations"
	AreaPhotos        Area = "photos"
	AreaRecordings    Area = "recordings"
	AreaFinance       Area = "finance"
	AreaLocation      Area = "location"
	AreaHealth        Area = "health"
	AreaJournal       Area = "journal"
	AreaSearch        Area = "search"

	// AreaOther is for tables that belong to none of the above, such as
	// accounts, configuration and calendars. A table is listed under it on
	// purpose, so that a new table has to be looked at, and a test fails for
	// one that is not listed anywhere.
	AreaOther Area = "other"
)

func AreaOf

func AreaOf(table string) (Area, bool)

AreaOf is the area a table belongs to, and whether the table is listed at all. A table that is not listed is counted as other when measured; the test over the migrations keeps that from happening.

type AreaSize

type AreaSize struct {
	Area       Area
	TableCount int
	SizeBytes  int64
}

AreaSize is the size of the tables of one area.

func AreaSizesOf

func AreaSizesOf(relations []models.StorageRelationSize, databaseSizeBytes int64) []AreaSize

AreaSizesOf adds the tables up by area, every area present and the largest first. What the database holds beyond its tables (the catalog, write-ahead log pending, sequences) is counted as other, so that the areas add up to the size of the database.

type DayTotal

type DayTotal struct {
	Day       time.Time
	SizeBytes int64
}

DayTotal is everything the server holds on one UTC day: the database and, when they are on a disk the server measures, the files.

func DayTotals

func DayTotals(samples []models.StorageUsageSample, isFilesCounted bool) []DayTotal

DayTotals adds each day's samples up: the database's total and, when isFilesCounted, every kind of file. A day that has neither is left out. Oldest first.

func DiskDayTotals

func DiskDayTotals(samples []models.StorageUsageSample, diskLabel string) []DayTotal

DiskDayTotals is what one disk held on each UTC day it was measured, from its own samples. A disk's fill date is fitted through these and not through the database and file totals, because the disk also gains and loses what the server does not count: files moved to another store, logs, other programs. Oldest first.

type Disk

type Disk struct {
	DiskLabel string

	// IsMeasured is false for storage the server cannot ask how full it is,
	// such as an object store, and for a platform that cannot tell. The
	// sizes are then zero and mean nothing.
	IsMeasured     bool
	DiskTotalBytes int64
	DiskFreeBytes  int64
}

Disk is where the server's own files are, measured when the server can.

func Disks

func Disks(configuration *config.Configuration) []Disk

Disks measures the file systems the server writes to: its data directory, the directory the blob store keeps files in when that is on another file system, and says that an object store is not measured. On a small server the data directory, PostgreSQL's data and the object store's are one disk, so one measure covers them; a database on another machine is not measured at all.

func (Disk) DiskUsedBytes

func (self Disk) DiskUsedBytes() int64

DiskUsedBytes is what the disk holds, whoever wrote it.

type FileKindSize

type FileKindSize struct {
	FileKind  string
	SizeBytes int64
}

FileKindSize is what the rows say one kind of file holds.

func FileKindsOf

func FileKindsOf(measured []models.StorageFileKindSize) []FileKindSize

FileKindsOf puts the measured kinds in the order of models.StorageFileKinds, every kind present.

type Growth

type Growth struct {
	// SampleCount is how many daily totals the line was fitted through.
	SampleCount int

	// IsProjectable is false when there were too few samples, or all on one
	// day, for a line.
	IsProjectable bool

	// GrowthBytesPerDay is the slope of the line; negative when the server
	// is shrinking.
	GrowthBytesPerDay float64

	// CurrentSizeBytes is the newest total, from which the projections go
	// forward at the fitted rate.
	CurrentSizeBytes int64
	In30DaysBytes    int64
	In90DaysBytes    int64
	In365DaysBytes   int64
}

Growth is a line fitted through the recent daily totals.

func Fit

func Fit(totals []DayTotal, now time.Time) Growth

Fit fits a least-squares line through the daily totals of the last ProjectionWindowDays days up to now.

func (Growth) FullOn

func (self Growth) FullOn(freeBytes int64, isMeasured bool, now time.Time) (*time.Time, float64)

FullOn is the day a disk with freeBytes of room fills at this growth (the disk's own, see DiskDayTotals), and how many days away that is. It is nil when the totals are not projectable, when the server is not growing, or when the disk is not measured.

type PersonFiles

type PersonFiles struct {
	// UserID is empty for the files no account owns: mail that is in no
	// mailbox, and what the per-person sums do not add up to because a photo
	// kept once is counted for each person who has it.
	UserID    string
	FileKinds []FileKindSize
	SizeBytes int64
}

PersonFiles is what one person's files hold, by kind. The database is not measured per person.

func PeopleOf

func PeopleOf(measured []models.StoragePersonFileSize, totals []FileKindSize) []PersonFiles

PeopleOf groups the per-person sums into one row a person, the largest first, and adds a row with no person for what the totals hold beyond the people. A kind that the people add up to more than the total (a photo that two accounts both hold is stored once) leaves nothing over for that kind.

type Snapshot

type Snapshot struct {
	DatabaseSizeBytes int64
	Areas             []AreaSize
	FileKinds         []FileKindSize
	FileSizeBytes     int64
	People            []PersonFiles
}

Snapshot is what the database and the blob store hold at one moment.

func Measure

func Measure(tx db.Transaction, isByPersonMeasured bool) (*Snapshot, error)

Measure reads the sizes the database keeps. Table sizes come from the catalog, and each file kind is a sum over the size column of a table that has one row per file. Sizes by person join mail to the mailboxes it is filed in, which reads every message, so they are read only when isByPersonMeasured is set.

type Warning

type Warning struct {
	DiskLabel     string
	WarningDays   int
	DaysUntilFull float64
	FullOn        time.Time

	// Growth is the disk's own, the line its fill date comes from.
	Growth Growth
}

Warning is a warning to send about a disk.

func DueWarnings

func DueWarnings(samples []models.StorageUsageSample, disks []Disk, previous map[string]*models.StorageDiskWarning, now time.Time) (due []Warning, recovered []string)

DueWarnings says which warnings to send now and which disks have recovered. Each disk's fill date comes from a line through its own samples. A disk projected to fill within thirty days is warned about once, and again when it comes within seven; previous is the warning last sent for each disk. A disk no longer projected to fill within thirty days is in recovered, so that its next warning is sent as a first.

Jump to

Keyboard shortcuts

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