Beispiel #1
0
func main() {
	flag.Parse()
	if flag.NArg() != 1 {
		usage()
	}

	path := flag.Args()[0]

	w, err := whisper.Open(path)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("%s:\n", path)
	fmt.Printf("Maximum retention:\t%d\n", w.Header.Metadata.MaxRetention)
	fmt.Printf("X-Files factor:\t\t%f\n", w.Header.Metadata.XFilesFactor)
	fmt.Printf("Number of archives:\t%d\n", w.Header.Metadata.ArchiveCount)
	fmt.Printf("Aggregation method:\t%s\n", w.Header.Metadata.AggregationMethod.String())
	fmt.Printf("\n")

	for i, archive := range w.Header.Archives {
		fmt.Printf("Archive %d:\n", i)
		fmt.Printf("Seconds per point:\t%d\n", archive.SecondsPerPoint)
		fmt.Printf("Points:\t\t\t%d\n", archive.Points)
		fmt.Printf("Retention:\t\t%d\n", archive.SecondsPerPoint*archive.Points)
	}
}
Beispiel #2
0
func main() {
	now := uint(time.Now().Unix())
	yesterday := uint(time.Now().Add(-24 * time.Hour).Unix())
	flag.UintVar(&from, "from", yesterday, "Unix epoch time of the beginning of the requested interval. (default: 24 hours ago)")
	flag.UintVar(&until, "until", now, "Unix epoch time of the end of the requested interval. (default: now)")
	flag.Parse()

	if flag.NArg() != 1 {
		usage()
	}

	path := flag.Args()[0]
	fromTime := uint32(from)
	untilTime := uint32(until)

	w, err := whisper.Open(path)
	if err != nil {
		log.Fatal(err)
	}

	interval, points, err := w.FetchUntil(fromTime, untilTime)

	fmt.Printf("Values in interval %+v\n", interval)
	for i, p := range points {
		fmt.Printf("%d %v\n", i, p)
	}
	return
}
Beispiel #3
0
func main() {
	flag.Parse()

	if flag.NArg() < 2 {
		usage()
	}

	now := uint32(time.Now().Unix())

	// Open the database
	args := flag.Args()
	path := args[0]
	w, err := whisper.Open(path)
	if err != nil {
		log.Fatal(err)
	}

	// Parse all the points
	var points = make([]whisper.Point, len(args)-1)
	for i, p := range args[1:] {
		splitP := strings.Split(p, ":")

		if len(splitP) != 2 {
			log.Fatalf("invalid point %s: %s", p, err)
		}

		// Parse the timestamp
		var timestamp uint32
		timestampString := splitP[0]
		if timestampString == "N" {
			timestamp = now
		} else {
			timestamp64, err := strconv.ParseUint(timestampString, 10, 32)
			if err != nil {
				log.Fatalf("invalid timestamp %s: %s", timestampString, err)
			}
			timestamp = uint32(timestamp64)
		}

		// Parse the value
		value, err := strconv.ParseFloat(splitP[1], 64)
		if err != nil {
			log.Fatalf("invalid value: %s", splitP[1])
		}

		points[i] = whisper.Point{timestamp, value}
	}

	fmt.Printf("Updating with points: %v\n", points)

	err = w.UpdateMany(points)
	if err != nil {
		log.Fatal("failed to update database: %s", err)
	}

}
Beispiel #4
0
func main() {
	flag.Parse()
	filename := flag.Arg(0)
	if filename == "" {
		flag.Usage()
		os.Exit(1)
	}

	db, err := whisper.Open(filename)
	if err != nil {
		fmt.Println("could not open database:", err)
		os.Exit(1)
	}
	defer db.Close()
	dumpHeader(db)
	dumpArchiveHeaders(db)
}