whisper

package
v0.0.0-...-82e8091 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2014 License: Apache-2.0 Imports: 10 Imported by: 27

Documentation

Overview

Package whisper implements an interface to the whisper database format used by the Graphite project (https://github.com/graphite-project/)

Index

Constants

View Source
const (
	DefaultXFilesFactor      = 0.5
	DefaultAggregationMethod = AggregationAverage
)

Variables

View Source
var (
	ErrNoArchives         = errors.New("archive list must contain at least one archive.")
	ErrDuplicateArchive   = errors.New("no archive may be a duplicate of another.")
	ErrUnevenPrecision    = errors.New("higher precision archives must evenly divide in to lower precision.")
	ErrLowRetention       = errors.New("lower precision archives must cover a larger time interval than higher precision.")
	ErrInsufficientPoints = errors.New("archive has insufficient points to aggregate to a lower precision")
)

Functions

This section is empty.

Types

type AggregationMethod

type AggregationMethod uint32

The AggregationMethod type describes how values are aggregated from one Whisper archive to another.

const (
	AggregationUnknown AggregationMethod = 0 // Unknown aggregation method
	AggregationAverage AggregationMethod = 1 // Aggregate using averaging
	AggregationSum     AggregationMethod = 2 // Aggregate using sum
	AggregationLast    AggregationMethod = 3 // Aggregate using the last value
	AggregationMax     AggregationMethod = 4 // Aggregate using the maximum value
	AggregationMin     AggregationMethod = 5 // Aggregate using the minimum value
)

Valid aggregation methods

func (AggregationMethod) String

func (m AggregationMethod) String() (s string)

type ArchiveInfo

type ArchiveInfo struct {
	Offset          uint32 // The byte offset of the archive within the database
	SecondsPerPoint uint32 // The number of seconds of elapsed time represented by a data point
	Points          uint32 // The number of data points
}

ArchiveInfo holds metadata about a single archive within a whisper database

func NewArchiveInfo

func NewArchiveInfo(secondsPerPoint, points uint32) ArchiveInfo

NewArchiveInfo returns a new ArchiveInfo with a zero offset.

func ParseArchiveInfo

func ParseArchiveInfo(archiveString string) (ArchiveInfo, error)

ParseArchiveInfo returns an ArchiveInfo represented by the string.

The string must consist of two numbers, the precision and retention, separated by a colon (:).

Both the precision and retention strings accept a unit suffix. Acceptable suffixes are: "s" for second, "m" for minute, "h" for hour, "d" for day, "w" for week, and "y" for year.

The precision string specifies how large of a time interval is represented by a single point in the archive.

The retention string specifies how long points are kept in the archive. If no suffix is given for the retention it is taken to mean a number of points and not a duration.

func (ArchiveInfo) Retention

func (a ArchiveInfo) Retention() uint32

Retention is the retention period of the archive in seconds.

func (ArchiveInfo) Size

func (a ArchiveInfo) Size() uint32

Size is the size of the archive in bytes.

type CreateOptions

type CreateOptions struct {
	// The XFiles factor to use. DefaultXFilesFactor if not set.
	XFilesFactor float32

	// The archive aggregation method to use. DefaultAggregationMethod if not set.
	AggregationMethod AggregationMethod

	// If true, allocate a sparse archive.
	Sparse bool
}

CreateOptions sets the options used to create a new archive.

func DefaultCreateOptions

func DefaultCreateOptions() CreateOptions
type Header struct {
	Metadata Metadata      // General metadata about the database
	Archives []ArchiveInfo // Information about each of the archives in the database, in order of precision
}

Header contains all the metadata about a whisper database.

type Interval

type Interval struct {
	FromTimestamp  uint32 // Start of the interval in seconds since the epoch
	UntilTimestamp uint32 // End of the interval in seconds since the epoch
	Step           uint32 // Step size in seconds
}

Interval repsents a time interval with a step.

func (Interval) Duration

func (i Interval) Duration() time.Duration

Duration returns the interval length as a time.Duration

func (Interval) From

func (i Interval) From() time.Time

From returns the interval's FromTimestamp as a time.Time

func (Interval) Until

func (i Interval) Until() time.Time

Until returns the interval's UntilTimestamp as a time.Time

type Metadata

type Metadata struct {
	// Aggregation method used. See the Aggregation* constants.
	AggregationMethod AggregationMethod

	// The maximum retention period.
	MaxRetention uint32

	// The minimum percentage of known values required to aggregate.
	XFilesFactor float32

	// The number of archives in the database.
	ArchiveCount uint32
}

Metadata holds metadata that's common to an entire whisper database

type Point

type Point struct {
	Timestamp uint32  // Timestamp in seconds past the epoch
	Value     float64 // Data point value
}

Point is a single datum stored in a whisper database.

func NewPoint

func NewPoint(t time.Time, v float64) Point

NewPoint constructs a new Point at time t with value v.

func (Point) Time

func (p Point) Time() time.Time

Time returns the time for the Point p

type Whisper

type Whisper struct {
	Header Header
	// contains filtered or unexported fields
}

Whisper represents a handle to a whisper database.

func Create

func Create(path string, archives []ArchiveInfo, options CreateOptions) (*Whisper, error)

Create attempts to create a new database at the given filepath.

func Open

func Open(path string) (*Whisper, error)

Open opens an existing whisper database. It returns an error if the file does not exist or is not a valid whisper archive.

func OpenWhisper

func OpenWhisper(f io.ReadWriteSeeker) (*Whisper, error)

OpenWhisper opens an existing Whisper database from the given ReadWriteSeeker.

func (*Whisper) Close

func (w *Whisper) Close() error

Close closes a whisper database.

func (*Whisper) DumpArchive

func (w *Whisper) DumpArchive(n int) ([]Point, error)

func (*Whisper) Fetch

func (w *Whisper) Fetch(from uint32) (Interval, []Point, error)

Fetch is equivalent to calling FetchUntil with until set to time.Now()

func (*Whisper) FetchTime

func (w *Whisper) FetchTime(from time.Time) (Interval, []Point, error)

FetchTime is like Fetch but accepts a time.Time

func (*Whisper) FetchUntil

func (w *Whisper) FetchUntil(from, until uint32) (interval Interval, points []Point, err error)

FetchUntil returns all points between two timestamps

func (*Whisper) FetchUntilTime

func (w *Whisper) FetchUntilTime(from, until time.Time) (Interval, []Point, error)

FetchUntilTime is like FetchUntil but accepts time.Time

func (*Whisper) SetAggregationMethod

func (w *Whisper) SetAggregationMethod(m AggregationMethod) error

SetAggregationMethod updates the aggregation method for the database

func (*Whisper) Update

func (w *Whisper) Update(point Point) error

Update writes a single datapoint to the whisper database

func (*Whisper) UpdateMany

func (w *Whisper) UpdateMany(points []Point) error

UpdateMany write a slice of datapoints to the whisper database. The points do not have to be unique or sorted. If two points cover the same time interval the last point encountered will be retained.

Jump to

Keyboard shortcuts

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