Beispiel #1
0
func start(ctx *cli.Context) {
	if ctx.Bool("profile") {
		pcfg := profile.Config{
			CPUProfile:   true,
			MemProfile:   true,
			BlockProfile: true,
			ProfilePath:  ".",
		}
		p := profile.Start(&pcfg)
		defer p.Stop()
	}
	initLogrus(ctx)
	log.Info("Starting fullerite...")

	c, err := config.ReadConfig(ctx.String("config"))
	if err != nil {
		return
	}
	collectors := startCollectors(c)
	handlers := startHandlers(c)

	internalServer := internalserver.New(c, &handlers)
	go internalServer.Run()

	metrics := make(chan metric.Metric)
	readFromCollectors(collectors, metrics)

	hook := NewLogErrorHook(metrics)
	log.Logger.Hooks.Add(hook)

	relayMetricsToHandlers(handlers, metrics)
}
Beispiel #2
0
func start(ctx *cli.Context) {
	if ctx.Bool("profile") {
		defer profile.Start(profile.CPUProfile).Stop()
		defer profile.Start(profile.MemProfile).Stop()
		defer profile.Start(profile.BlockProfile).Stop()
		defer profile.Start(profile.ProfilePath("."))
	}
	quit := make(chan bool)
	initLogrus(ctx)
	log.Info("Starting fullerite...")

	c, err := config.ReadConfig(ctx.String("config"))
	if err != nil {
		return
	}
	handlers := createHandlers(c)
	hook := NewLogErrorHook(handlers)
	log.Logger.Hooks.Add(hook)

	startHandlers(handlers)
	collectors := startCollectors(c)

	collectorStatChan := make(chan metric.CollectorEmission)

	internalServer := internalserver.New(c,
		handlerStatFunc(handlers),
		readCollectorStat(collectorStatChan))

	go internalServer.Run()

	readFromCollectors(collectors, handlers, collectorStatChan)

	<-quit
}
Beispiel #3
0
func start(ctx *cli.Context) {
	if ctx.Bool("profile") {
		pcfg := profile.Config{
			CPUProfile:   true,
			MemProfile:   true,
			BlockProfile: true,
			ProfilePath:  ".",
		}
		p := profile.Start(&pcfg)
		defer p.Stop()
	}
	initLogrus(ctx)
	log.Info("Starting fullerite...")

	c, err := config.ReadConfig(ctx.String("config"))
	if err != nil {
		return
	}
	collectors := startCollectors(c)
	handlers := startHandlers(c)
	metrics := make(chan metric.Metric)
	readFromCollectors(collectors, metrics)
	for metric := range metrics {
		// Writing to handlers' channels. Sending metrics is
		// handled asynchronously in handlers' Run functions.
		writeToHandlers(handlers, metric)
	}
}
Beispiel #4
0
func TestStartCollectorsMixedConfig(t *testing.T) {
	logrus.SetLevel(logrus.ErrorLevel)
	conf, _ := config.ReadConfig(tmpTestFakeFile)
	collectors := startCollectors(conf)

	for _, c := range collectors {
		assert.Equal(t, c.Name(), "Test", "Only create valid collectors")
	}
}
Beispiel #5
0
func visualize(ctx *cli.Context) {
	initLogrus(ctx)
	log.Info("Visualizing fullerite...")

	if len(ctx.Args()) == 0 {
		log.Error("You need a collector file to visualize!, see 'fullerite help visualize'")
		return
	}

	c, err := config.ReadConfig(ctx.String("config"))
	if err != nil {
		return
	}

	// Setup AdHoc Collector config from context and args
	collectorFile, _ := filepath.Abs(ctx.Args()[0])
	configMap := make(map[string]interface{})
	configMap["interval"] = ctx.Int("interval")
	configMap["collectorFile"] = collectorFile

	// Start collector and handlers
	collector := startCollector("AdHoc", c, configMap)
	handlers := startHandlers(c)

	// Create channel for incoming metrics
	metrics := make(chan metric.Metric)
	defer close(metrics)

	// Read the metrics from the AdHoc collector
	go readFromCollector(collector, metrics)
	go relayMetricsToHandlers(handlers, metrics)

	// Stop collecting after `die-after` duration expires
	quitChannel := make(chan bool, 1)
	defer close(quitChannel)

	dieAfter := time.Duration(ctx.Int("die-after"))
	time.AfterFunc(dieAfter*time.Second, func() {
		log.Info("Quitting...")
		quitChannel <- true
	})
	// Wait to quit
	for {
		select {
		case <-quitChannel:
			return
		}
	}
}
Beispiel #6
0
func start(ctx *cli.Context) {
	initLogrus(ctx)
	log.Info("Starting beatit...")

	runtime.GOMAXPROCS(runtime.NumCPU())

	c, err := config.ReadConfig(ctx.String("config"))
	if err != nil {
		return
	}

	var handlers []handler.Handler
	for i := 0; i < ctx.Int("num-tasks"); i++ {
		if ctx.Bool("graphite") {
			h := newHandler("Graphite", c, ctx.Int("num-datapoints"))
			go h.Run()
			handlers = append(handlers, h)
		}
		if ctx.Bool("signalfx") {
			h := newHandler("SignalFx", c, ctx.Int("num-datapoints"))
			go h.Run()
			handlers = append(handlers, h)
		}
		if ctx.Bool("datadog") {
			h := newHandler("Datadog", c, ctx.Int("num-datapoints"))
			go h.Run()
			handlers = append(handlers, h)
		}
	}

	t := time.Tick(1 * time.Second)
	count := 0
	for _ = range t {
		if count++; count > ctx.Int("time") {
			os.Exit(0)
		}
		metrics := generateMetrics(ctx.String("prefix"),
			ctx.Int("num-metrics"),
			ctx.Int("num-datapoints"),
			ctx.Bool("randomize"))
		for _, h := range handlers {
			go sendMetrics(h, metrics)
		}
	}
}
Beispiel #7
0
func TestParseBadConfig(t *testing.T) {
	_, err := config.ReadConfig(tmpTestBadFile)
	assert.NotNil(t, err, "should fail")
}
Beispiel #8
0
func TestParseGoodConfig(t *testing.T) {
	_, err := config.ReadConfig(tmpTestGoodFile)
	assert.Nil(t, err, "should succeed")
}