Documentation
¶
Overview ¶
Package whispertool implements Graphite's Whisper database format.
This package is created for the CLI tool in the cmd/whispertool subpackage.
Note this package's API is incompatible to github.com/go-graphite/go-whisper.
Index ¶
- Constants
- Variables
- type AggregationMethod
- type AppendTaker
- type AppenderTo
- type ArchiveInfo
- func (a *ArchiveInfo) AppendTo(dst []byte) []byte
- func (a ArchiveInfo) Equal(b ArchiveInfo) bool
- func (a *ArchiveInfo) MaxRetention() Duration
- func (a *ArchiveInfo) NumberOfPoints() uint32
- func (a *ArchiveInfo) SecondsPerPoint() Duration
- func (a ArchiveInfo) String() string
- func (a *ArchiveInfo) TakeFrom(src []byte) ([]byte, error)
- type ArchiveInfoList
- type Duration
- type Header
- func (h *Header) AggregationMethod() AggregationMethod
- func (h *Header) AppendTo(dst []byte) []byte
- func (h *Header) ArchiveInfoList() ArchiveInfoList
- func (h *Header) ExpectedFileSize() int64
- func (h *Header) MaxRetention() Duration
- func (h *Header) Size() int64
- func (h *Header) String() string
- func (h *Header) TakeFrom(src []byte) ([]byte, error)
- func (h *Header) XFilesFactor() float32
- type Option
- type Point
- type Points
- func (pp *Points) AppendTo(dst []byte) []byte
- func (pp Points) Diff(qq Points) (Points, Points)
- func (pp Points) Equal(qq Points) bool
- func (pp Points) Len() int
- func (pp Points) Less(i, j int) bool
- func (pp Points) String() string
- func (pp Points) Swap(i, j int)
- func (pp *Points) TakeFrom(src []byte) ([]byte, error)
- func (pp Points) Values() []Value
- type TakerFrom
- type TimeSeries
- func (ts *TimeSeries) AppendTo(dst []byte) []byte
- func (ts *TimeSeries) DiffPoints(ts2 *TimeSeries) (Points, Points)
- func (ts *TimeSeries) DiffPointsExcludeSrcNaN(ts2 *TimeSeries) (Points, Points)
- func (ts *TimeSeries) Equal(ts2 *TimeSeries) bool
- func (ts *TimeSeries) EqualTimeRangeAndStep(ts2 *TimeSeries) bool
- func (ts *TimeSeries) FromTime() Timestamp
- func (ts *TimeSeries) Points() Points
- func (ts *TimeSeries) Step() Duration
- func (ts *TimeSeries) String() string
- func (ts *TimeSeries) TakeFrom(src []byte) ([]byte, error)
- func (ts *TimeSeries) UntilTime() Timestamp
- func (ts *TimeSeries) Values() []Value
- type Timestamp
- func (t Timestamp) Add(d Duration) Timestamp
- func (t *Timestamp) AppendTo(dst []byte) []byte
- func (t Timestamp) String() string
- func (t Timestamp) Sub(u Timestamp) Duration
- func (t *Timestamp) TakeFrom(src []byte) ([]byte, error)
- func (t Timestamp) ToStdTime() time.Time
- func (t Timestamp) Truncate(d Duration) Timestamp
- type Value
- type WantLargerBufferError
- type Whisper
- func (w *Whisper) AggregationMethod() AggregationMethod
- func (w *Whisper) ArchiveInfoList() ArchiveInfoList
- func (w *Whisper) Close() error
- func (w *Whisper) Fetch(from, until Timestamp) (*TimeSeries, error)
- func (w *Whisper) FetchFromArchive(arhiveID int, from, until, now Timestamp) (*TimeSeries, error)
- func (w *Whisper) GetAllRawUnsortedPoints(archiveID int) (Points, error)
- func (w *Whisper) Header() *Header
- func (w *Whisper) MaxRetention() Duration
- func (w *Whisper) Sync() error
- func (w *Whisper) Update(t Timestamp, v Value) error
- func (w *Whisper) UpdateMany(points []Point) (err error)
- func (w *Whisper) UpdatePointForArchive(archiveID int, t Timestamp, v Value, now Timestamp) error
- func (w *Whisper) UpdatePointsForArchive(points []Point, archiveID int, now Timestamp) error
- func (w *Whisper) XFilesFactor() float32
Constants ¶
const ( Second Duration = 1 Minute = 60 * Second Hour = 60 * Minute Day = 24 * Hour Week = 7 * Day Year = 365 * Day )
Duration constants
const ArchiveIDBest = -1
ArchiveIDBest is used to find the best archive for time range in FetchFromArchive.
const UTCTimeLayout = "2006-01-02T15:04:05Z"
Timestamp format layout used in this package. Note time zone is fixed to "Z".
Variables ¶
var ErrArchiveIDOutOfRange = errors.New("archive ID out of range")
ErrArchiveIDOutOfRange is the error when an archive ID if out of range.
var Now = time.Now
Now is a function which returns the current time. You can mock this function in tests.
Functions ¶
This section is empty.
Types ¶
type AggregationMethod ¶
type AggregationMethod int
AggregationMethod is the type of aggregation used in a whisper database. Note: 4 bytes long in Whisper Header, 1 byte long in Archive Header
const ( Average AggregationMethod = iota + 1 Sum Last Max Min First Mix // only used in whisper header Percentile // only used in archive header )
AggregationMethod constants
func AggregationMethodString ¶
func AggregationMethodString(s string) (AggregationMethod, error)
AggregationMethodString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func AggregationMethodValues ¶
func AggregationMethodValues() []AggregationMethod
AggregationMethodValues returns all values of the enum
func (AggregationMethod) IsAAggregationMethod ¶
func (i AggregationMethod) IsAAggregationMethod() bool
IsAAggregationMethod returns "true" if the value is listed in the enum definition. "false" otherwise
func (AggregationMethod) String ¶
func (i AggregationMethod) String() string
type AppendTaker ¶
type AppendTaker interface {
AppenderTo
TakerFrom
}
AppendTaker is the interface that groups AppendTo and TakeFrom methods.
type AppenderTo ¶
AppenderTo is the interface for serializing an object and appends the encoded bytes to dst.
type ArchiveInfo ¶
type ArchiveInfo struct {
// contains filtered or unexported fields
}
ArchiveInfo is a retention level. ArchiveInfo levels describe a given archive in the database. How detailed it is and how far back it records.
func NewArchiveInfo ¶
func NewArchiveInfo(secondsPerPoint Duration, numberOfPoints uint32) ArchiveInfo
NewArchiveInfo creats a retention.
func ParseArchiveInfo ¶
func ParseArchiveInfo(s string) (ArchiveInfo, error)
ParseArchiveInfo parses a single retention definition as you would find in the storage-schemas.conf of a Carbon install. Note that this only parses a single retention definition. An example input is "10s:2h". If you would like to parse multiple retention definitions like "10s:2h,1m:1d", use ParseRetentions instead.
func (*ArchiveInfo) AppendTo ¶
func (a *ArchiveInfo) AppendTo(dst []byte) []byte
AppendTo appends encoded bytes of a to dst and returns the extended buffer.
AppendTo method implements the AppenderTo interface.
func (ArchiveInfo) Equal ¶
func (a ArchiveInfo) Equal(b ArchiveInfo) bool
Equal returns whether or not a equals to b.
func (*ArchiveInfo) MaxRetention ¶
func (a *ArchiveInfo) MaxRetention() Duration
MaxRetention returns the whole duration of a.
func (*ArchiveInfo) NumberOfPoints ¶
func (a *ArchiveInfo) NumberOfPoints() uint32
NumberOfPoints returns the number of points in a.
func (*ArchiveInfo) SecondsPerPoint ¶
func (a *ArchiveInfo) SecondsPerPoint() Duration
SecondsPerPoint returns the duration of the step of a.
func (ArchiveInfo) String ¶
func (a ArchiveInfo) String() string
String returns the spring representation of a.
type ArchiveInfoList ¶
type ArchiveInfoList []ArchiveInfo
ArchiveInfoList is a slice of Retention.
func ParseArchiveInfoList ¶
func ParseArchiveInfoList(s string) (ArchiveInfoList, error)
ParseArchiveInfoList parses multiple retention definitions as you would find in the storage-schemas.conf of a Carbon install. Note that this parses multiple retention definitions. An example input is "10s:2h,1m:1d".
See: http://graphite.readthedocs.org/en/1.0/config-carbon.html#storage-schemas-conf
func (ArchiveInfoList) Equal ¶
func (aa ArchiveInfoList) Equal(bb ArchiveInfoList) bool
Equal returns whether or not aa equals to bb.
func (ArchiveInfoList) String ¶
func (aa ArchiveInfoList) String() string
String returns the spring representation of rr.
type Duration ¶
type Duration int32
Duration is seconds between two Timestamps.
func ParseDuration ¶
ParseDuration parses a Duration string.
func (*Duration) AppendTo ¶
AppendTo appends encoded bytes of d to dst and returns the extended buffer.
type Header ¶
type Header struct {
// contains filtered or unexported fields
}
Header respresents a whisper file header.
func NewHeader ¶
func NewHeader(aggregationMethod AggregationMethod, xFilesFactor float32, archiveInfoList ArchiveInfoList) (*Header, error)
NewHeader creates and retruns a whisper file header. It returns an error if validations of passed arguments failed.
func (*Header) AggregationMethod ¶
func (h *Header) AggregationMethod() AggregationMethod
AggregationMethod returns the aggregation method of the whisper file.
func (*Header) AppendTo ¶
AppendTo appends encoded bytes of h to dst and returns the extended buffer.
AppendTo method implements the AppenderTo interface.
func (*Header) ArchiveInfoList ¶
func (h *Header) ArchiveInfoList() ArchiveInfoList
ArchiveInfoList returns the archive info list of the whisper file.
func (*Header) ExpectedFileSize ¶
ExpectedFileSize returns the expected file size from h.
func (*Header) MaxRetention ¶
MaxRetention returns the max retention of the whisper file.
func (*Header) String ¶
String returns the string representation of h in LTSV format [1].
[1] Labeled Tab-separated Values http://ltsv.org/
func (*Header) TakeFrom ¶
TakeFrom updates ts from encoded bytes in src and returns the rest of src.
TakeFrom method implements the TakerFrom interface. If there is an error, it may be of type *WantLargerBufferError.
func (*Header) XFilesFactor ¶
XFilesFactor returns the xFilesFactor of the whisper file.
type Option ¶
type Option func(*Whisper)
Option is the type for options for creating or opening a whisper file.
func WithOpenFileFlag ¶
WithOpenFileFlag sets the flag for opening the file. This option is useful only when no WithInMemory is passed. Without this option, the default value is os.O_RDWR | os.O_CREATE | os.O_EXCL for Create and os.O_RDWR for Open.
type Point ¶
Point represent a data point in whisper databases.
func (*Point) AppendTo ¶
AppendTo appends encoded bytes of p to dst and returns the extended buffer.
AppendTo method implements the AppenderTo interface.
func (Point) Equal ¶
Equals returns whether or not p equals to q. It returns true if time and value of p equals to q. For comparison of value, Value's Equals method is used.
type Points ¶
type Points []Point
Points represents a slice of Point.
func (*Points) AppendTo ¶
AppendTo appends encoded bytes of pp to dst and returns the extended buffer.
AppendTo method implements the AppenderTo interface.
func (Points) Less ¶
Less reports whether the element with index i should sort before the element with index j. Implements sort.Interface.
type TakerFrom ¶
TakerFrom is the interface for deserializing an object and returns the rest of src.
If there is an error, it may be of type *WantLargerBufferError.
type TimeSeries ¶
type TimeSeries struct {
// contains filtered or unexported fields
}
TimeSeries is a result from Fetch.
func NewTimeSeries ¶
func NewTimeSeries(fromTime, untilTime Timestamp, step Duration, values []Value) *TimeSeries
NewTimeSeries returns a new TimeSeries.
func (*TimeSeries) AppendTo ¶
func (ts *TimeSeries) AppendTo(dst []byte) []byte
AppendTo appends encoded bytes of ts to dst and returns the extended buffer.
AppendTo method implements the AppenderTo interface.
func (*TimeSeries) DiffPoints ¶
func (ts *TimeSeries) DiffPoints(ts2 *TimeSeries) (Points, Points)
DiffPoints returns the different points between ts and us.
func (*TimeSeries) DiffPointsExcludeSrcNaN ¶
func (ts *TimeSeries) DiffPointsExcludeSrcNaN(ts2 *TimeSeries) (Points, Points)
DiffPointsExcludeSrcNaN returns the different points between ts and us excluding points of source NaN values.
func (*TimeSeries) Equal ¶
func (ts *TimeSeries) Equal(ts2 *TimeSeries) bool
Equal returns whether or not ts equals to us.
func (*TimeSeries) EqualTimeRangeAndStep ¶
func (ts *TimeSeries) EqualTimeRangeAndStep(ts2 *TimeSeries) bool
EqualTimeRangeAndStep returns whether or not all of FromTime(), UntilTime() and Step() are the same between ts and us.
func (*TimeSeries) FromTime ¶
func (ts *TimeSeries) FromTime() Timestamp
FromTime returns the start time of ts.
func (*TimeSeries) Step ¶
func (ts *TimeSeries) Step() Duration
Step returns the duration between points in ts.
func (*TimeSeries) String ¶
func (ts *TimeSeries) String() string
String returns the string representation of ts.
func (*TimeSeries) TakeFrom ¶
func (ts *TimeSeries) TakeFrom(src []byte) ([]byte, error)
TakeFrom updates ts from encoded bytes in src and returns the rest of src.
TakeFrom method implements the TakerFrom interface. If there is an error, it may be of type *WantLargerBufferError.
func (*TimeSeries) UntilTime ¶
func (ts *TimeSeries) UntilTime() Timestamp
UntilTime returns the end time of ts.
type Timestamp ¶
type Timestamp uint32
Timestamp is the Unix timestamp, the number of seconds elapsed since January 1, 1970 UTC.
func ParseTimestamp ¶
ParseTimestamp parses timestamp in "2006-01-02T15:04:05Z" format. Note only "Z" is allowed for timezone.
func TimestampFromStdTime ¶
StdTimeToTimestamp returns t as a Timestamp.
func (*Timestamp) AppendTo ¶
AppendTo appends encoded bytes of t to dst and returns the extended buffer.
AppendTo method implements the AppenderTo interface.
func (*Timestamp) TakeFrom ¶
TakeFrom updates t from encoded bytes in src and returns the rest of src.
TakeFrom method implements the TakerFrom interface. If there is an error, it may be of type *WantLargerBufferError.
type Value ¶
type Value float64
Value represents a value of Point.
func (Value) Add ¶
Add returns the sum (v + u) if both v and u is not NaN. It returns u if v is NaN, v if u is NaN.
func (*Value) AppendTo ¶
AppendTo appends encoded bytes of v to dst and returns the extended buffer.
AppendTo method implements the AppenderTo interface.
func (Value) Diff ¶
Diff returns the difference (v - u) if both v and u is not NaN. It returns NaN if either v or u is NaN.
type WantLargerBufferError ¶
type WantLargerBufferError struct {
WantedBufSize int
}
WantLargerBufferError records the length of bytes wanted to deserialize.
If WantedByteLen is zero, it means the length wanted is unkown.
func (*WantLargerBufferError) Error ¶
func (e *WantLargerBufferError) Error() string
Error returns the error message for e.
type Whisper ¶
type Whisper struct {
// contains filtered or unexported fields
}
Whisper represents a Whisper database file.
func Create ¶
func Create(filename string, archiveInfoList []ArchiveInfo, aggregationMethod AggregationMethod, xFilesFactor float32, opts ...Option) (*Whisper, error)
Create creates a whisper database file.
func Open ¶
Open opens an existing whisper database file. In the current implementation, the whole content is read after opening the file. This behavior may be changed in the future.
func (*Whisper) AggregationMethod ¶
func (w *Whisper) AggregationMethod() AggregationMethod
AggregationMethod returns the aggregation method of the whisper file.
func (*Whisper) ArchiveInfoList ¶
func (w *Whisper) ArchiveInfoList() ArchiveInfoList
ArchiveInfoList returns the archive info list of the whisper file.
func (*Whisper) Close ¶
Close closes the file. For the file created with WithInMemory, this is a no-op.
func (*Whisper) Fetch ¶
func (w *Whisper) Fetch(from, until Timestamp) (*TimeSeries, error)
Fetch fetches points from the best archive for the specified time range.
It fetches points in range between `from` (exclusive) and `until` (inclusive).
func (*Whisper) FetchFromArchive ¶
func (w *Whisper) FetchFromArchive(arhiveID int, from, until, now Timestamp) (*TimeSeries, error)
FetchFromArchive fetches points in the specified archive and the time range.
FetchFromArchive fetches points from archive specified with `arhiveID`. It fetches points in range between `from` (exclusive) and `until` (inclusive). If `now` is zero, the current time is used.
func (*Whisper) GetAllRawUnsortedPoints ¶
GetAllRawUnsortedPoints returns the raw unsorted points. This is provided for the debugging or investination purpose.
func (*Whisper) MaxRetention ¶
MaxRetention returns the max retention of the whisper file.
func (*Whisper) Sync ¶
Sync flushes modifications on the memory buffer to the file and sync commits the content to the storage by calling os.File.Sync(). Note it is caller's responsibility to call Sync and the modification will be lost without calling Sync. For the file created with WithInMemory, this is a no-op.
func (*Whisper) Update ¶
Update a value in the database.
If the timestamp is in the future or outside of the maximum retention it will fail immediately.
func (*Whisper) UpdateMany ¶
UpdateMany updates points in the best matching archives.
func (*Whisper) UpdatePointForArchive ¶
UpdatePointForArchive updates one point in the specified archive.
func (*Whisper) UpdatePointsForArchive ¶
UpdatePointsForArchive updates points in the specified archive.
If archiveID is ArchiveIDBest, points are first splitted for the best matching archives and update the corresponding archives.
Note this does NOT update points whose timestamp is out of the timestamp range of the specified archive. This behavior is not compatible to Whisper.UpdateMany in github.com/go-graphite/go-whisper.
func (*Whisper) XFilesFactor ¶
XFilesFactor returns the xFilesFactor of the whisper file.