Exemplo n.º 1
0
func main() {
	flag.Parse()

	conn, err := network.Dial(*host, network.ClientOptions{})
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	defer conn.Close()

	rateLimiter := make(chan int, *rate)

	go func() {
		ticker := time.NewTicker(time.Second)
		for {
			select {
			case <-ticker.C:
				for i := 0; i < *rate; i++ {
					rateLimiter <- i
				}
			}
		}
	}()

	nSent := 0
	for {
		if nSent >= *total && *total > 0 {
			break
		}
		<-rateLimiter

		vl := api.ValueList{
			Identifier: api.Identifier{
				Host:   "tagvalue" + strconv.Itoa(int(rand.Int31n(int32(*tagVariance)))),
				Plugin: "golang" + strconv.Itoa(int(rand.Int31n(int32(*nMeasurments)))),
				Type:   "gauge",
			},
			Time:     time.Now(),
			Interval: 10 * time.Second,
			Values:   []api.Value{api.Gauge(42.0)},
		}
		ctx := context.TODO()
		if err := conn.Write(ctx, &vl); err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		conn.Flush()
		nSent = nSent + 1
	}

	fmt.Println("Number of points sent:", nSent)
}
Exemplo n.º 2
0
func main() {
	if len(os.Args) < 2 {
		log.Fatalf("[ERROR] %s requires more arguments!\n", os.Args[0])
	}

	addresses := strings.Fields(os.Args[1])
	clients = make([]*network.Client, len(addresses))
	index := 0
	for _, address := range addresses {
		client, err := network.Dial(address, network.ClientOptions{})
		if err != nil {
			log.Printf("[WARN] unable to connect to %s!\n", address)
			continue
		}

		clients[index] = client
		index += 1
		defer client.Close()
	}

	e := exec.NewExecutor()
	e.VoidCallback(sendNetUsage, exec.Interval())
	e.Run()
}