Exemplo n.º 1
0
func main() {

	sourceURL := flag.String("sourceUrl", "http://server1.kabletown.net:8086", "The influxdb url and port")
	targetURL := flag.String("targetUrl", "http://server2.kabletown.net:8086", "The influxdb url and port")
	database := flag.String("database", "all", "Sync a specific database")
	days := flag.Int("days", 0, "Number of days in the past to sync (today - x days), 0 is all")
	flag.Parse()
	fmt.Printf("syncing %v to %v for %v database(s) for the past %v day(s)\n", *sourceURL, *targetURL, *database, *days)
	sourceClient, err := influx.NewHTTPClient(influx.HTTPConfig{
		Addr: *sourceURL,
	})
	if err != nil {
		fmt.Printf("Error creating influx sourceClient: %v\n", err)
		os.Exit(1)
	}
	targetClient, err := influx.NewHTTPClient(influx.HTTPConfig{
		Addr: *targetURL,
	})
	if err != nil {
		fmt.Printf("Error creating influx targetClient: %v\n", err)
		os.Exit(1)
	}
	chSize := 1
	if *database == "all" {
		chSize = 3
	}

	ch := make(chan string)

	switch *database {
	case "all":
		go syncCsDb(ch, sourceClient, targetClient, *days)
		go syncDsDb(ch, sourceClient, targetClient, *days)
		go syncDailyDb(ch, sourceClient, targetClient, *days)
	case "cache_stats":
		go syncCsDb(ch, sourceClient, targetClient, *days)
	case "deliveryservice_stats":
		go syncDsDb(ch, sourceClient, targetClient, *days)
	case "daily_stats":
		go syncDailyDb(ch, sourceClient, targetClient, *days)
	}

	for i := 1; i <= chSize; i++ {
		fmt.Println(<-ch)
	}

	fmt.Println("Traffic Stats has been synced!")
}
Exemplo n.º 2
0
func influxConnect(config StartupConfig, runningConfig RunningConfig) (influx.Client, error) {
	// Connect to InfluxDb
	var urls []string

	for _, InfluxHost := range runningConfig.InfluxDBProps {
		u := fmt.Sprintf("http://%s:%d", InfluxHost.Fqdn, InfluxHost.Port)
		urls = append(urls, u)
	}

	for len(urls) > 0 {
		n := rand.Intn(len(urls))
		url := urls[n]
		urls = append(urls[:n], urls[n+1:]...)

		conf := influx.HTTPConfig{
			Addr:     url,
			Username: config.InfluxUser,
			Password: config.InfluxPassword,
		}

		con, err := influx.NewHTTPClient(conf)
		if err != nil {
			errHndlr(err, ERROR)
			continue
		}

		return con, nil
	}

	err := errors.New("Could not connect to any of the InfluxDb servers that are ONLINE in traffic ops.")
	return nil, err
}
Exemplo n.º 3
0
func InitDB() (client.Client, error) {
	clnt, err = client.NewHTTPClient(client.HTTPConfig{
		Addr: config.C.InfluxDBUrl,
	})
	if err != nil {
		return clnt, fmt.Errorf("Failed to connect to InfluxDB: %s", err)
	}
	_, err := queryDB(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s", MyDB))
	if err != nil {
		return clnt, fmt.Errorf("Failed to create database: %s", err)
	}
	return clnt, nil
}
Exemplo n.º 4
0
func (s *Service) NewClient() (c client.Client, err error) {
	tries := 0
	for tries < len(s.configs) {
		tries++
		config := s.configs[s.i]
		s.i = (s.i + 1) % len(s.configs)
		c, err = client.NewHTTPClient(config)
		if err != nil {
			continue
		}
		_, _, err = c.Ping(config.Timeout)
		if err != nil {
			continue
		}
		return
	}
	return
}
func main() {

	influxURL := flag.String("url", "http://localhost:8086", "The influxdb url and port")
	replication := flag.String("replication", "3", "The number of nodes in the cluster")
	flag.Parse()
	fmt.Printf("creating datbases for influxUrl: %v with a replication of %v\n", *influxURL, *replication)
	client, err := influx.NewHTTPClient(influx.HTTPConfig{
		Addr: *influxURL,
	})
	if err != nil {
		fmt.Printf("Error creating influx client: %v", err)
		panic("could not create influx client")
	}

	createCacheStats(client, replication)
	createDailyStats(client, replication)
	createDeliveryServiceStats(client, replication)

}
Exemplo n.º 6
0
func (m *MockInfluxDBService) NewClient() (client.Client, error) {
	return client.NewHTTPClient(client.HTTPConfig{
		Addr: m.ts.URL,
	})

}