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() } }
func Ping() (common.Point, error) { start := time.Now().UTC() point := common.Point{Time: start} d := net.Dialer{Timeout: 5 * time.Second} conn, err := d.Dial("tcp", "8.8.8.8:53") if err != nil { point.Latency = 5 * time.Second point.Error = 1 point.Interface = ief return point, nil } point.Latency = time.Since(start) point.Error = 0 ief, err = getInterface(strings.Split(conn.LocalAddr().String(), ":")[0]) if err != nil { return point, fmt.Errorf("Failed to get interface: %s", err.Error()) } point.Interface = ief conn.Close() return point, nil }