Documentation ¶
Overview ¶
Package whisper implements Graphite's Whisper database format
Index ¶
- Constants
- Variables
- func Compare(file1 string, file2 string, now int, ignoreBuffer bool, quarantinesRaw string, ...) (msg string, err error)
- func Debug(compress, bitsWrite bool)
- func GenDataPointSlice() []dataPoint
- func GenTestArchive(buf []byte, ret Retention) *archiveInfo
- type AggregationMethod
- type MixAggregationSpec
- type Options
- type Retention
- type Retentions
- type TimeSeries
- type TimeSeriesPoint
- type Whisper
- func Create(path string, retentions Retentions, aggregationMethod AggregationMethod, ...) (whisper *Whisper, err error)
- func CreateWithOptions(path string, retentions Retentions, aggregationMethod AggregationMethod, ...) (whisper *Whisper, err error)
- func Open(path string) (whisper *Whisper, err error)
- func OpenWithOptions(path string, options *Options) (whisper *Whisper, err error)
- func (whisper *Whisper) AggregationMethod() AggregationMethod
- func (whisper *Whisper) CheckEmpty(fromTime, untilTime int) (exist bool, err error)
- func (whisper *Whisper) CheckIntegrity() error
- func (whisper *Whisper) Close() error
- func (whisper *Whisper) CompressTo(dstPath string) error
- func (whisper *Whisper) Dump(all, showDecompressionInfo bool)
- func (whisper *Whisper) Fetch(fromTime, untilTime int) (timeSeries *TimeSeries, err error)
- func (whisper *Whisper) FetchByAggregation(fromTime, untilTime int, spec *MixAggregationSpec) (timeSeries *TimeSeries, err error)
- func (whisper *Whisper) File() *os.File
- func (dstw *Whisper) FillClassic(srcw *Whisper) error
- func (dstw *Whisper) FillCompressed(srcw *Whisper) error
- func (whisper *Whisper) GetDiscardedPointsSinceOpen() uint32
- func (whisper *Whisper) HasMatchingConfigs(rets Retentions, aggr AggregationMethod, xff float32, options *Options) bool
- func (whisper *Whisper) IsCompressed() bool
- func (whisper *Whisper) MaxRetention() int
- func (whisper *Whisper) MetadataSize() int
- func (whisper *Whisper) Retentions() []Retention
- func (whisper *Whisper) Size() int
- func (whisper *Whisper) StartTime() int
- func (whisper *Whisper) Update(value float64, timestamp int) (err error)
- func (whisper *Whisper) UpdateConfig(rets Retentions, aggr AggregationMethod, xff float32, options *Options) (err error)
- func (whisper *Whisper) UpdateMany(points []*TimeSeriesPoint) (err error)
- func (whisper *Whisper) UpdateManyForArchive(points []*TimeSeriesPoint, targetRetention int) (err error)
- func (whisper *Whisper) WriteHeaderCompressed() (err error)
- func (whisper *Whisper) XFilesFactor() float32
Constants ¶
const ( // size constants ByteSize = 1 IntSize = 4 FloatSize = 4 Float64Size = 8 PointSize = 12 MetadataSize = 16 ArchiveInfoSize = 12 )
const ( Seconds = 1 Minutes = 60 Hours = 3600 Days = 86400 Weeks = 86400 * 7 Years = 86400 * 365 )
const MaxCompressedPointSize = PointSize + 2
In worst case scenario all data points would required 2 bytes more space after compression, this buffer size make sure that it's always big enough to contain the compressed result
Variables ¶
var ( CompressedMetadataSize = 28 + FreeCompressedMetadataSize FreeCompressedMetadataSize = 16 VersionSize = 1 CompressedArchiveInfoSize = 92 + FreeCompressedArchiveInfoSize FreeCompressedArchiveInfoSize = 36 BlockRangeSize = 16 // One can see that blocks that extend longer than two // hours provide diminishing returns for compressed size. A // two-hour block allows us to achieve a compression ratio of // 1.37 bytes per data point. // 4.1.2 Compressing values // Gorilla: A Fast, Scalable, In-Memory Time Series Database DefaultPointsPerBlock = 7200 // recommended by the gorilla paper algorithm )
var Now = time.Now
Functions ¶
func Compare ¶
func Compare( file1 string, file2 string, now int, ignoreBuffer bool, quarantinesRaw string, verbose bool, strict bool, muteThreshold int, ) (msg string, err error)
skipcq: RVV-A0005
func GenDataPointSlice ¶
func GenDataPointSlice() []dataPoint
func GenTestArchive ¶
Types ¶
type AggregationMethod ¶
type AggregationMethod int
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 )
const Unknown AggregationMethod = -1
func ParseAggregationMethod ¶
func ParseAggregationMethod(am string) AggregationMethod
func (AggregationMethod) String ¶
func (am AggregationMethod) String() string
type MixAggregationSpec ¶
type MixAggregationSpec struct { Method AggregationMethod Percentile float32 }
func (*MixAggregationSpec) String ¶
func (mas *MixAggregationSpec) String() string
type Options ¶
type Options struct { Sparse bool FLock bool FlockType int Compressed bool // It's a hint, used if the retention is big enough, more in // Retention.calculateSuitablePointsPerBlock PointsPerBlock int PointSize float32 InMemory bool InMemoryContent []byte OpenFileFlag *int MixAggregationSpecs []MixAggregationSpec MixAvgCompressedPointSizes map[int][]float32 SIMV bool // single interval multiple values IgnoreNowOnWrite bool }
type Retention ¶
type Retention struct {
// contains filtered or unexported fields
}
A retention level.
Retention levels describe a given archive in the database. How detailed it is and how far back it records.
func NewRetention ¶
func ParseRetentionDef ¶
Parse a retention definition as you would find in the storage-schemas.conf of a Carbon install. Note that this only parses a single retention definition, if you have multiple definitions (separated by a comma) you will have to split them yourself.
ParseRetentionDef("10s:14d") Retention{10, 120960}
See: http://graphite.readthedocs.org/en/1.0/config-carbon.html#storage-schemas-conf
func (*Retention) MaxRetention ¶
func (*Retention) NumberOfPoints ¶
func (*Retention) SecondsPerPoint ¶
func (*Retention) SetAvgCompressedPointSize ¶
type Retentions ¶
type Retentions []*Retention
TODO: maybe we should make it array of structs, rather than an array of struct pointers.
func MustParseRetentionDefs ¶
func MustParseRetentionDefs(retentionDefs string) Retentions
func NewRetentionsNoPointer ¶
func NewRetentionsNoPointer(r2 []Retention) Retentions
func ParseRetentionDefs ¶
func ParseRetentionDefs(retentionDefs string) (Retentions, error)
func (Retentions) Equal ¶
func (r1 Retentions) Equal(r2 Retentions) bool
func (Retentions) Len ¶
func (r Retentions) Len() int
func (Retentions) Swap ¶
func (r Retentions) Swap(i, j int)
type TimeSeries ¶
type TimeSeries struct {
// contains filtered or unexported fields
}
func (*TimeSeries) FromTime ¶
func (ts *TimeSeries) FromTime() int
func (*TimeSeries) PointPointers ¶
func (ts *TimeSeries) PointPointers() []*TimeSeriesPoint
func (*TimeSeries) Points ¶
func (ts *TimeSeries) Points() []TimeSeriesPoint
func (*TimeSeries) Step ¶
func (ts *TimeSeries) Step() int
func (*TimeSeries) String ¶
func (ts *TimeSeries) String() string
func (*TimeSeries) UntilTime ¶
func (ts *TimeSeries) UntilTime() int
func (*TimeSeries) Values ¶
func (ts *TimeSeries) Values() []float64
type TimeSeriesPoint ¶
type Whisper ¶
type Whisper struct { Extended bool // TODO: improve NonFatalErrors []error // contains filtered or unexported fields }
Represents a Whisper database file.
func Create ¶
func Create(path string, retentions Retentions, aggregationMethod AggregationMethod, xFilesFactor float32) (whisper *Whisper, err error)
Create a new Whisper database file and write it's header.
func CreateWithOptions ¶
func CreateWithOptions(path string, retentions Retentions, aggregationMethod AggregationMethod, xFilesFactor float32, options *Options) (whisper *Whisper, err error)
CreateWithOptions is more customizable create function
avgCompressedPointSize specification order:
Options.PointSize < Retention.avgCompressedPointSize < Options.MixAggregationSpecs.AvgCompressedPointSize
func OpenWithOptions ¶
func (*Whisper) AggregationMethod ¶
func (whisper *Whisper) AggregationMethod() AggregationMethod
Return raw aggregation method
func (*Whisper) CheckEmpty ¶
Check a TimeSeries has a points for a given time span from the file.
func (*Whisper) CheckIntegrity ¶
func (*Whisper) CompressTo ¶
For archive.Buffer handling, CompressTo assumes a simple archive layout that higher archive will propagate to lower archive. [wrong]
CompressTo should stop compression/return errors when runs into any issues (if feasible).
func (*Whisper) Fetch ¶
func (whisper *Whisper) Fetch(fromTime, untilTime int) (timeSeries *TimeSeries, err error)
Fetch a TimeSeries for a given time span from the file.
func (*Whisper) FetchByAggregation ¶
func (whisper *Whisper) FetchByAggregation(fromTime, untilTime int, spec *MixAggregationSpec) (timeSeries *TimeSeries, err error)
func (*Whisper) FillClassic ¶
func (*Whisper) FillCompressed ¶
FillCompressed backfill cwhisper files from srcw. The old and new whisper should have the same retention policies.
func (*Whisper) GetDiscardedPointsSinceOpen ¶
Returns updated amount of out-of-order discarded points since opening whisper file
func (*Whisper) HasMatchingConfigs ¶
func (whisper *Whisper) HasMatchingConfigs(rets Retentions, aggr AggregationMethod, xff float32, options *Options) bool
func (*Whisper) IsCompressed ¶
func (*Whisper) MaxRetention ¶
Return max retention in seconds
func (*Whisper) MetadataSize ¶
Calculate the number of bytes the metadata section will be.
func (*Whisper) Size ¶
Calculate the total number of bytes the Whisper file should be according to the metadata.
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) UpdateConfig ¶
func (whisper *Whisper) UpdateConfig(rets Retentions, aggr AggregationMethod, xff float32, options *Options) (err error)
func (*Whisper) UpdateMany ¶
func (whisper *Whisper) UpdateMany(points []*TimeSeriesPoint) (err error)
func (*Whisper) UpdateManyForArchive ¶
func (whisper *Whisper) UpdateManyForArchive(points []*TimeSeriesPoint, targetRetention int) (err error)
Note: for compressed format, extensions is triggered after update is done, so updates of the same data set being done in one UpdateManyForArchive call would have different result in file than in many UpdateManyForArchive calls.