Beispiel #1
0
func InitWorker() {
	go func() {
		err = datastore.Flush()
		if err != nil {
			log.Fatalf("Failed to flush: %s", err.Error())
		}
	}()
	c := make(chan common.Point, 100000)
	go consumer(c)
	ticker := time.NewTicker(200 * time.Millisecond)
	go func() {
		for _ = range ticker.C {
			go producer(c)
		}
	}()
}
Beispiel #2
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()
	}
}