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 }
func TestMain(m *testing.M) { // viper.SetDefault("kapacitor-address", "http://localhost:9092") viper.SetDefault("kapacitor-address", "http://172.28.128.4:9092") err := kapacitor.Init() if err != nil { fmt.Printf("Failed to init - '%v' skipping tests\n", err) os.Exit(0) } os.Exit(m.Run()) }