Exemplo n.º 1
0
func TestCollectorPrefix(t *testing.T) {
	logrus.SetLevel(logrus.ErrorLevel)
	c := make(map[string]interface{})
	c["interval"] = 1
	c["prefix"] = "px."
	collector := collector.New("Test")
	collector.SetInterval(1)
	collector.Configure(c)

	collectorChannel := map[string]chan metric.Metric{
		"Test": make(chan metric.Metric),
	}

	testHandler := handler.New("Log")
	testHandler.SetCollectorChannels(collectorChannel)

	var wg sync.WaitGroup
	wg.Add(2)
	go func() {
		defer wg.Done()
		collector.Channel() <- metric.New("hello")
		close(collector.Channel())
	}()
	go func() {
		defer wg.Done()
		testMetric := <-collectorChannel["Test"]
		assert.Equal(t, "px.hello", testMetric.Name)
	}()
	readFromCollector(collector, []handler.Handler{testHandler})
	wg.Wait()
}
Exemplo n.º 2
0
func newHandler(name string, c config.Config, dps int) handler.Handler {
	h := handler.New(name)
	h.SetInterval(1)
	h.SetMaxBufferSize(dps)
	h.Configure(c.Handlers[name])
	return h
}
Exemplo n.º 3
0
func startHandler(name string, globalConfig config.Config, config map[string]interface{}) handler.Handler {
	log.Debug("Starting handler ", name)
	handler := handler.New(name)

	// apply any global configs
	handler.SetInterval(globalConfig.Interval)
	handler.SetPrefix(globalConfig.Prefix)
	handler.SetDefaultDimensions(globalConfig.DefaultDimensions)

	// now apply the handler level configs
	handler.Configure(config)

	go handler.Run()
	return handler
}
Exemplo n.º 4
0
func startHandler(name string, globalConfig config.Config, instanceConfig map[string]interface{}) handler.Handler {
	log.Info("Starting handler ", name)
	handlerInst := handler.New(name)
	if handlerInst == nil {
		return nil
	}

	// apply any global configs
	handlerInst.SetInterval(config.GetAsInt(globalConfig.Interval, handler.DefaultInterval))
	handlerInst.SetPrefix(globalConfig.Prefix)
	handlerInst.SetDefaultDimensions(globalConfig.DefaultDimensions)

	// now apply the handler level configs
	handlerInst.Configure(instanceConfig)

	go handlerInst.Run()
	return handlerInst
}
Exemplo n.º 5
0
func createHandler(name string, globalConfig config.Config, instanceConfig map[string]interface{}) handler.Handler {
	handlerInst := handler.New(name)
	if handlerInst == nil {
		return nil
	}

	// apply any global configs
	handlerInst.SetInterval(config.GetAsInt(globalConfig.Interval, handler.DefaultInterval))
	handlerInst.SetPrefix(globalConfig.Prefix)
	handlerInst.SetDefaultDimensions(globalConfig.DefaultDimensions)

	// now apply the handler level configs
	handlerInst.Configure(instanceConfig)

	// now run a listener channel for each collector
	handlerInst.InitListeners(globalConfig)

	return handlerInst
}
Exemplo n.º 6
0
func startHandlers(c Config) (handlers []handler.Handler) {
	log.Info("Starting handlers...")
	for name, config := range c.Handlers {
		handler := handler.New(name)

		// apply any global configs
		handler.SetInterval(c.Interval)
		handler.SetPrefix(c.Prefix)
		handler.SetDefaultDimensions(c.DefaultDimensions)

		// now apply the handler level configs
		handler.Configure(&config)

		handlers = append(handlers, handler)

		log.Info("Running ", handler)
		go handler.Run()
	}
	return handlers
}
Exemplo n.º 7
0
func buildHandler(name string) handler.Handler {
	log.Println("Building handler", name)
	handler := handler.New(name)
	return handler
}