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

	log.Printf("Configuration loaded from file: %s", configFilePath)
	config := configuration.Load(configFilePath)
	signal.Handle(func() {
		config = configuration.Load("config.json")
		log.Printf("Reloading configuration from: %s", configFilePath)
	})

	tickerChannel := time.NewTicker(time.Second * time.Duration(config.Interval)).C

	for {
		select {
		case <-tickerChannel:
			for _, redisConfig := range config.Redis {
				address := fmt.Sprintf("%s:%d", redisConfig.Host, redisConfig.Port)
				var name = ""
				if redisConfig.Alias != "" {
					name = redisConfig.Alias
				} else {
					name = redisConfig.Host
				}
				go info(address, name, config)
			}
		}
	}
}
Exemplo n.º 2
0
func TestLoad(t *testing.T) {
	expected := &configuration.Configuration{
		Interval: 1,
		Redis: []configuration.Redis{
			configuration.Redis{
				Host:  "redis_1",
				Port:  6379,
				Alias: "master",
			},
			configuration.Redis{
				Host:  "redis_2",
				Port:  6379,
				Alias: "slave",
			},
		},
		Metrics: []string{
			"used_memory",
			"mem_fragmentation_ratio",
			"db0.keys",
		},
		Statsd: configuration.Statsd{
			Host: "statsd",
			Port: 8125,
		},
	}

	config := configuration.Load("../config.json")

	if !reflect.DeepEqual(expected, &config) {
		t.Errorf("Expected:\n\t%v\nbut got:\n\t%v\n", expected, config)
	}
}