Esempio n. 1
0
func startLogvac(ccmd *cobra.Command, args []string) error {
	// initialize logger
	lumber.Level(lumber.LvlInt(config.LogLevel)) // for clients using lumber too
	config.Log = lumber.NewConsoleLogger(lumber.LvlInt(config.LogLevel))

	// initialize logvac
	logvac.Init()

	// setup authenticator
	err := authenticator.Init()
	if err != nil {
		return fmt.Errorf("Authenticator failed to initialize - %v", err)
	}

	// initialize drains
	err = drain.Init()
	if err != nil {
		return fmt.Errorf("Drain failed to initialize - %v", err)
	}

	// initializes collectors
	err = collector.Init()
	if err != nil {
		return fmt.Errorf("Collector failed to initialize - %v", err)
	}

	err = api.Start(collector.CollectHandler)
	if err != nil {
		return fmt.Errorf("Api failed to initialize - %v", err)
	}

	return nil
}
Esempio n. 2
0
// Test writing and getting data
func TestPublish(t *testing.T) {
	lumber.Level(lumber.LvlInt("fatal"))
	err := mistInitialize()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	// create test messages
	messages := []logvac.Message{
		logvac.Message{
			Time:     time.Now(),
			UTime:    time.Now().UnixNano(),
			Id:       "myhost",
			Tag:      "test[bolt]",
			Type:     "",
			Priority: 4,
			Content:  "This is a test message",
		},
		logvac.Message{
			Time:     time.Now(),
			UTime:    time.Now().UnixNano(),
			Id:       "myhost",
			Tag:      "test[expire]",
			Type:     "deploy",
			Priority: 4,
			Content:  "This is another test message",
		},
	}

	// write test messages
	drain.Publisher.Publish(messages[0])
	drain.Publisher.Publish(messages[1])
}
Esempio n. 3
0
func startHoarder(ccmd *cobra.Command, args []string) error {
	// convert the log level
	logLvl := lumber.LvlInt(viper.GetString("log-level"))

	// configure the logger
	lumber.Prefix("[hoader]")
	lumber.Level(logLvl)

	// enable/start garbage collection if age config was changed
	if ccmd.Flag("clean-after").Changed {
		lumber.Debug("Starting garbage collector (data older than %vs)...\n", ccmd.Flag("clean-after").Value)

		// start garbage collector
		go collector.Start()
	}

	// set, and initialize, the backend driver
	if err := backends.Initialize(); err != nil {
		lumber.Error("Failed to initialize backend - %v", err)
		return err
	}

	// start the API
	if err := api.Start(); err != nil {
		lumber.Fatal("Failed to start API: ", err.Error())
		return err
	}

	return nil
}
Esempio n. 4
0
// TestMain
func TestMain(m *testing.M) {
	lumber.Level(lumber.LvlInt("fatal"))

	server.StartTCP(testAddr, nil)

	//
	os.Exit(m.Run())
}
Esempio n. 5
0
func startPulse(ccmd *cobra.Command, args []string) error {
	// re-initialize logger
	lumber.Level(lumber.LvlInt(viper.GetString("log-level")))

	plex := plexer.NewPlexer()

	if viper.GetString("mist-address") != "" {
		mist, err := mist.New(viper.GetString("mist-address"), viper.GetString("mist-token"))
		if err != nil {
			return fmt.Errorf("Mist failed to start - %s", err.Error())
		}
		plex.AddObserver("mist", mist.Publish)
		defer mist.Close()
	}

	plex.AddBatcher("influx", influx.Insert)

	err := pulse.Listen(viper.GetString("server-listen-address"), plex.Publish)
	if err != nil {
		return fmt.Errorf("Pulse failed to start - %s", err.Error())
	}
	// begin polling the connected servers
	pollSec := viper.GetInt("poll-interval")
	if pollSec == 0 {
		pollSec = 60
	}
	go pulse.StartPolling(nil, nil, time.Duration(pollSec)*time.Second, nil)

	queries := []string{
		"CREATE DATABASE statistics",
		"CREATE RETENTION POLICY one_day ON statistics DURATION 8h REPLICATION 1 DEFAULT",
		fmt.Sprintf("CREATE RETENTION POLICY one_week ON statistics DURATION %dw REPLICATION 1", viper.GetInt("retention")), // todo: ALTER as well?
	}

	for _, query := range queries {
		_, err := influx.Query(query)
		if err != nil {
			return fmt.Errorf("Failed to query influx - %s", err.Error())
		}
	}

	go influx.KeepContinuousQueriesUpToDate()

	if viper.GetString("kapacitor-address") != "" {
		err := kapacitor.Init()
		if err != nil {
			return fmt.Errorf("Kapacitor failed to start - %s", err.Error())
		}
	}

	err = api.Start()
	if err != nil {
		return fmt.Errorf("Api failed to start - %s", err.Error())
	}

	return nil
}
Esempio n. 6
0
func TestMain(m *testing.M) {

	// manually configure
	http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
	viper.Set("backend", "file:///tmp/hoarder_test")
	viper.Set("listen-addr", testAddr)
	viper.Set("token", "secret")
	lumber.Level(lumber.LvlInt("fatal"))

	// empty test dir
	os.RemoveAll("/tmp/hoarder_test")
	backends.Initialize()
	// start api
	go api.Start()
	<-time.After(time.Second)
	rtn := m.Run()

	// empty test dir
	os.RemoveAll("/tmp/hoarder_test")

	os.Exit(rtn)
}
Esempio n. 7
0
func (self Nanobox) Init() error {
	// we want to see nanobox-router logs
	lumber.Level(lumber.LvlInt(config.LogLevel))

	// configure upstream cert checks
	router.IgnoreUpstreamCerts = config.ProxyIgnore

	// start http proxy
	err := router.StartHTTP(config.RouteHttp)
	if err != nil {
		return err
	}
	config.Log.Info("Proxy listening at http://%s...", config.RouteHttp)

	// start https proxy
	err = router.StartTLS(config.RouteTls)
	if err != nil {
		return err
	}
	config.Log.Info("Proxy listening at https://%s...", config.RouteTls)

	return nil
}
Esempio n. 8
0
func setLogLevel() {
	switch level {
	case "TRACE":
		lumber.Level(0)
	case "DEBUG":
		lumber.Level(1)
	case "INFO":
		lumber.Level(2)
	case "WARN":
		lumber.Level(3)
	case "ERROR":
		lumber.Level(4)
	case "FATAL":
		lumber.Level(5)
	default:
		lumber.Info("the log level provided (" + level + ") is not available, defaulting to INFO")
	}
}
Esempio n. 9
0
func init() {
	Pulse.Flags().StringP("http-listen-address", "H", httpAddress, "Http listen address")
	viper.BindPFlag("http-listen-address", Pulse.Flags().Lookup("http-listen-address"))
	Pulse.Flags().StringP("server-listen-address", "S", serverAddress, "Server listen address")
	viper.BindPFlag("server-listen-address", Pulse.Flags().Lookup("server-listen-address"))
	Pulse.Flags().StringP("influx-address", "i", influxAddress, "InfluxDB server address")
	viper.BindPFlag("influx-address", Pulse.Flags().Lookup("influx-address"))
	Pulse.Flags().StringP("kapacitor-address", "k", kapacitorAddress, "Kapacitor server address (http://127.0.0.1:9092)")
	viper.BindPFlag("kapacitor-address", Pulse.Flags().Lookup("kapacitor-address"))
	Pulse.Flags().StringP("mist-address", "m", mistAddress, "Mist server address")
	viper.BindPFlag("mist-address", Pulse.Flags().Lookup("mist-address"))
	Pulse.Flags().StringP("mist-token", "M", mistToken, "Mist server token")
	viper.BindPFlag("mist-token", Pulse.Flags().Lookup("mist-token"))
	Pulse.Flags().StringP("log-level", "l", logLevel, "Level at which to log")
	viper.BindPFlag("log-level", Pulse.Flags().Lookup("log-level"))
	Pulse.Flags().StringP("cors-allow", "C", corsAllow, "Sets the 'Access-Control-Allow-Origin' header")
	viper.BindPFlag("cors-allow", Pulse.Flags().Lookup("cors-allow"))
	Pulse.Flags().BoolP("server", "s", server, "Run as server")
	viper.BindPFlag("server", Pulse.Flags().Lookup("server"))
	Pulse.Flags().BoolP("insecure", "I", insecure, "Run insecure")
	viper.BindPFlag("insecure", Pulse.Flags().Lookup("insecure"))

	Pulse.Flags().StringP("token", "t", token, "Security token (recommend placing in config file)")
	viper.BindPFlag("token", Pulse.Flags().Lookup("token"))
	Pulse.Flags().IntP("poll-interval", "p", pollInterval, "Interval to request stats from clients")
	viper.BindPFlag("poll-interval", Pulse.Flags().Lookup("poll-interval"))
	Pulse.Flags().IntP("aggregate-interval", "a", aggregateInterval, "Interval at which stats are aggregated")
	viper.BindPFlag("aggregate-interval", Pulse.Flags().Lookup("aggregate-interval"))
	Pulse.Flags().IntP("retention", "r", retention, "Number of weeks to store aggregated stats")
	viper.BindPFlag("retention", Pulse.Flags().Lookup("retention"))

	Pulse.Flags().StringVarP(&configFile, "config-file", "c", configFile, "Config file location for server")
	Pulse.Flags().BoolVarP(&version, "version", "v", version, "Print version info and exit")

	lumber.Level(lumber.LvlInt(viper.GetString("log-level")))
}
Esempio n. 10
0
func init() {
	log.Level(log.TRACE)
}