GithubHelp home page GithubHelp logo

robyoung / go-whisper Goto Github PK

View Code? Open in Web Editor NEW
57.0 5.0 31.0 51 KB

A Go port of Graphite's Whisper timeseries database

License: BSD 3-Clause "New" or "Revised" License

Go 97.53% Python 2.47%

go-whisper's Introduction

Go Whisper

Build Status

Go Whisper is a Go implementation of the Whisper database, which is part of the Graphite Project.

To create a new whisper database you must define it's retention levels (see: storage schemas), aggregation method and the xFilesFactor. The xFilesFactor specifies the fraction of data points in a propagation interval that must have known values for a propagation to occur.

Examples

Create a new whisper database in "/tmp/test.wsp" with two retention levels (1 second for 1 day and 1 hour for 5 weeks), it will sum values when propagating them to the next retention level, and it requires half the values of the first retention level to be set before they are propagated.

retentions, err := whisper.ParseRetentionDefs("1s:1d,1h:5w")
if err == nil {
  wsp, err := whisper.Create("/tmp/test.wsp", retentions, whisper.Sum, 0.5)
}

Alternatively you can open an existing whisper database.

wsp, err := whisper.Open("/tmp/test.wsp")

Once you have a whisper database you can set values at given time points. This sets the time point 1 hour ago to 12345.678.

offset, _ := time.ParseDuration("-1h")
wsp.Update(12345.678, int(time.Now().Add(offset).Unix()))

And you can retrieve time series from it. This example fetches a time series for the last 1 hour and then iterates through it's points.

offset, _ := time.ParseDuration("-1h")
series, err := wsp.Fetch(int(time.Now().Add(offset).Unix()), int(time.Now().Unix()))
if err != nil {
  // handle
}
for _, point := range series.Points() {
  fmt.Println(point.Time, point.Value)
}

Thread Safety

This implementation is not thread safe. Writing to a database concurrently will cause bad things to happen. It is up to the user to manage this in their application as they need to.

Licence

Go Whisper is licenced under a BSD Licence.

go-whisper's People

Contributors

charl avatar dgryski avatar jjneely avatar lomik avatar robyoung avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

go-whisper's Issues

Return NaN instead of 0 for nil values?

Perhaps have it configurable? That way the user of the library can make their own decision on what to do with missing data.

(We have a patch that does this, but we would clean it up if you wanted it as a pull request.)

Expose TimeSeries members?

We're in the process of prototyping a server that serves whisper data (from a carbon store typically) in the same way the carbon web frontend would do. For that purpose, we need to access the from and untiltime, plus step, as well as that it seemed handy to be able to directly access the values array.

Would a patch like this be acceptable to you?

--- a/whisper.go
+++ b/whisper.go
@@ -684,6 +684,22 @@ type TimeSeries struct {
        values    []float64
 }

+func (ts *TimeSeries) FromTime() int {
+       return ts.fromTime
+}
+
+func (ts *TimeSeries) UntilTime() int {
+       return ts.untilTime
+}
+
+func (ts *TimeSeries) Step() int {
+       return ts.step
+}
+
+func (ts *TimeSeries) Values() []float64 {
+       return ts.values
+}
+
 func (ts *TimeSeries) Points() []TimeSeriesPoint {
        points := make([]TimeSeriesPoint, len(ts.values))
        for i, value := range ts.values {

int/int64 conversions

Heya, I'm just beginning to use go-whisper, and I'm wondering if it would make sense to switch a lot of function's time parameters over to using int64?

Time.Unix seems to drive most of the code I'm writing (just like it's in most of the examples on the go-whisper readme!)... and Time.Unix returns an int64. This means my code is littered with int(t.Unix()) wrappers (and also the readme examples don't compile without that fix). Switching Update and Fetch to just use int64 themselves would seem to reduce friction.

Are there any reasons not to prefer int64? I guess someone using a different concept of "time" might find it unnecessary, that seems like the exception rather than the rule, and still doesn't seem like that case would be unduly burdened by int64.

morning

"To maintain a stable job and give the best of me, I must continue to train and provide my best effort to succeed as a very responsible professional capable of solving big and small problems."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.