Esempio n. 1
0
func Migrate() {
	iefs := []string{"lan", "wifi"}
	go func() {
		err = datastore.Flush()
		if err != nil {
			log.Fatalf("Failed to flush: %s", err.Error())
		}
	}()
	for _, ief := range iefs {
		log.Printf("Migrating %s...\n", ief)
		data, err := old_datastore.Read(ief, 10000*time.Hour)
		if err != nil {
			log.Fatalf("Failed to read: %s", err.Error())
		}
		log.Println("Done reading")
		var ops int
		ticker := time.NewTicker(5 * time.Second)
		go func() {
			for _ = range ticker.C {
				log.Printf("Writing %d points per second\n", ops/5)
				ops = 0
			}
		}()
		for t, status := range data {
			ops += 1
			point := common.Point{
				Time:      t,
				Interface: ief,
			}
			p99 := strconv.FormatFloat(status.Percentile99, 'f', -1, 64)
			point.Latency, err = time.ParseDuration(p99 + "s")
			if err != nil {
				log.Fatalf("Failed to parse duration:", err.Error())
			}

			if status.Uptime > 99.0 {
				point.Error = 0
			} else {
				point.Error = 1
			}
			datastore.Write(point)
		}
		ticker.Stop()
	}
}
Esempio n. 2
0
func consumer(c chan common.Point) {
	for {
		datastore.Write(<-c)
	}
}