Ejemplo n.º 1
0
// Files() will fill data from src into dst without overwriting data currently
// in dst, and always copying the highest resulution data no matter what time
// ranges.
// * source - path to the Whisper file
// * dest - path to the Whisper file
// * startTime - Unix time such as time.Now().Unix().  We fill from this time
//   walking backwards to the begining of the retentions.
func Files(source, dest string, startTime int) error {
	// Setup, open our files and error check
	dstWsp, err := whisper.Open(dest)
	if err != nil {
		return err
	}
	defer dstWsp.Close()
	srcWsp, err := whisper.Open(source)
	if err != nil {
		return err
	}
	defer srcWsp.Close()

	return OpenWSP(srcWsp, dstWsp, startTime)
}
Ejemplo n.º 2
0
func validateWhisper(path string, ts []*whisper.TimeSeriesPoint) error {
	wsp, err := whisper.Open(path)
	if err != nil {
		return err
	}
	defer wsp.Close()

	wspData, err := wsp.Fetch(0, int(time.Now().Unix()))
	if err != nil {
		return err
	}
	var flag error = nil
	for i, v := range wspData.Values() {
		// In order time points...should match what's in data
		if v == ts[i].Value {
			//log.Printf("Verifty %.2f == %.2f\n", v, ts[i].Value)
		} else if math.IsNaN(v) && math.IsNaN(ts[i].Value) {
			//log.Printf("Verifty %.2f == %.2f\n", v, ts[i].Value)
		} else {
			//log.Printf("Verifty %.2f != %.2f\n", v, ts[i].Value)
			if flag == nil {
				flag = fmt.Errorf("Whipser point %d is %f but should be %f\n", i, v, ts[i].Value)
			}
		}
	}

	return flag
}
Ejemplo n.º 3
0
// examine implements the WalkFunc type for our file system walk
func examine(path string, info os.FileInfo, err error) error {
	// Did the Walk function hit an error on this file?
	if err != nil {
		log.Printf("%s\n", err)
		return nil
	}

	// Sanity check our file
	if info.IsDir() {
		if strings.HasPrefix(path, ".") {
			return filepath.SkipDir
		}
		return nil
	}
	if !info.Mode().IsRegular() {
		// Not a regular file
		return nil
	}
	if !strings.HasSuffix(path, ".wsp") {
		// Not a Whisper Database
		return nil
	}

	wsp, err := whisper.Open(path)
	if err != nil {
		log.Printf("%s\n", err)
		return err
	}
	defer wsp.Close()

	ts, count, err := buckytools.FindValidDataPoints(wsp)
	if err != nil {
		log.Printf("%s\n", err)
		return err
	}

	if lastDP {
		if len(ts) > 0 {
			t := time.Unix(int64(ts[0].Time), 0).UTC().Format(time.RFC3339)
			fmt.Printf("%s: Most recent DP: %s\t%.2f\n",
				path, t, ts[0].Value)
		} else {
			fmt.Printf("%s: No valid data points\n", path)
		}
	}
	if debug {
		fmt.Printf("%s: %d data points used out of %d in %s\n",
			path, len(ts), count, flag.Arg(0))
	}
	if !debug && !lastDP && len(ts) == 0 {
		if metricName {
			fmt.Println(metrics.PathToMetric(path))
		} else {
			fmt.Println(path)
		}
	}

	return nil
}
Ejemplo n.º 4
0
func fetchFromFile(path string) ([]*whisper.TimeSeriesPoint, error) {
	// Init the datastructure we will load values into
	tsp := make([]*whisper.TimeSeriesPoint, 30)
	for i, _ := range tsp {
		point := new(whisper.TimeSeriesPoint)
		point.Value = math.NaN()
		tsp[i] = point
	}

	// Try to open the file
	wsp, err := whisper.Open(path)
	if err != nil {
		return tsp, err
	}
	defer wsp.Close()

	// Parse and fetch data from it
	ts, err := wsp.Fetch(0, int(time.Now().Unix()))
	if err != nil {
		return tsp, err
	}

	return ts.Points(), nil
}