Example #1
0
func TestEndToEnd(test *testing.T) {
	relay, err := relay.NewRelay(address, "relay.station.1")
	if err != nil {
		test.Errorf("unable to connect to server %v", err)
		return
	}
	defer relay.Close()

	relay.AddCollector("cpu", []string{"hi", "how", "are:you"}, randCollector())

	relay.AddCollector("ram", nil, randCollector())

	relay.AddCollector("disk", nil, randCollector())
	time.Sleep(time.Millisecond * 100)
	wait.Add(1)
	server.Poll([]string{"disk"})
	wait.Wait()

	wait.Add(2)
	server.Poll([]string{"ram", "cpu"})
	wait.Wait()

	wait.Add(3)
	server.Poll([]string{"ram", "cpu", "disk"})
	wait.Wait()

	if len(messages) != 3 {
		test.Errorf("Expected to recieve 3 messages but instead got %d", len(messages))
	}
	messages = []plexer.MessageSet{}
}
Example #2
0
func main() {
	host := ""
	id := ""
	collectors := []string{}
	cmd := &cobra.Command{
		Use:   "pulse-tester",
		Short: "insert dummy data to pulse",
		Run: func(ccmd *cobra.Command, args []string) {
			r, err := relay.NewRelay(host, id)
			if err != nil {
				fmt.Println(err)
				r.Close()
				return
			}

			for _, collector := range collectors {
				err = r.AddCollector(collector, nil, relay.NewPointCollector(randFunc))
				if err != nil {
					r.Close()
					return
				}
			}
			fmt.Println("started")
			<-time.After(10 * time.Hour)
		},
	}
	cmd.Flags().StringVar(&host, "host", "127.0.0.1:3000", "connection to pulse")
	cmd.Flags().StringVar(&id, "id", "computer1", "id of the host to insert into pulse")
	cmd.Flags().StringSliceVar(&collectors, "collectors", []string{"cpu_used", "ram_used"}, "fake data to insert into pulse")

	cmd.Execute()
}