Пример #1
0
func main() {
	rollrus.SetupLogging(os.Getenv("ROLLBAR_TOKEN"), os.Getenv("ENVIRONMENT"))

	config, err := NewIssConfig()
	if err != nil {
		log.Fatalln(err)
	}

	log.AddHook(&DefaultFieldsHook{log.Fields{"app": "log-iss", "source": config.Deploy}})

	auth, err := authenticater.NewBasicAuthFromString(config.Tokens)
	if err != nil {
		log.Fatalln(err)
	}

	forwarderSet := newForwarderSet(config)

	shutdownCh := make(shutdownCh)
	httpServer := newHTTPServer(config, auth, fix, forwarderSet)

	go awaitShutdownSignals(httpServer.shutdownCh, shutdownCh)

	go forwarderSet.Run()

	go func() {
		if err := httpServer.Run(); err != nil {
			log.Fatalln("Unable to start HTTP server:", err)
		}
	}()

	if config.LibratoOwner != "" && config.LibratoToken != "" {
		log.WithField("source", config.LibratoSource).Info("starting librato metrics reporting")
		go librato.Librato(
			config.MetricsRegistry,
			20*time.Second,
			config.LibratoOwner,
			config.LibratoToken,
			config.LibratoSource,
			[]float64{0.50, 0.95, 0.99},
			time.Millisecond,
		)
	}

	log.WithField("at", "start").Info()
	<-shutdownCh
	log.WithField("at", "drain").Info()
	httpServer.Wait()
	log.WithField("at", "exit").Info()
}
Пример #2
0
func UploadToLibrato(config *conf.LibratoConfiguration) {
	if config.Email != "" {
		hostname, err := os.Hostname()
		if err != nil {
			log.Fatalf("Unable to retrieve a hostname %s", err)
		}

		go librato.Librato(metrics.DefaultRegistry,
			30e9,          // interval
			config.Email,  // account email addres
			config.Token,  // auth token
			hostname,      // source
			[]float64{95}, // precentiles to send
			time.Millisecond)
	}
}
Пример #3
0
func (i *CLI) setupMetrics() {
	go travismetrics.ReportMemstatsMetrics()

	if i.Config.LibratoEmail != "" && i.Config.LibratoToken != "" && i.Config.LibratoSource != "" {
		i.logger.Info("starting librato metrics reporter")

		go librato.Librato(metrics.DefaultRegistry, time.Minute,
			i.Config.LibratoEmail, i.Config.LibratoToken, i.Config.LibratoSource,
			[]float64{0.95}, time.Millisecond)
	} else if !i.c.Bool("silence-metrics") {
		i.logger.Info("starting logger metrics reporter")

		go metrics.Log(metrics.DefaultRegistry, time.Minute,
			log.New(os.Stderr, "metrics: ", log.Lmicroseconds))
	}
}
Пример #4
0
func main() {
	toRecorder := make(chan Measurement)
	toWebsocket := make(chan Measurement)

	if config.LibratoEmail != "" && config.LibratoToken != "" && config.LibratoSource != "" {
		log.Println("fn=main metrics=librato")
		go librato.Librato(metrics.DefaultRegistry,
			10e9,                  // interval
			config.LibratoEmail,   // account owner email address
			config.LibratoToken,   // Librato API token
			config.LibratoSource,  // source
			[]float64{50, 95, 99}, // precentiles to send
			time.Millisecond,      // time unit
		)
	}

	if config.LogStderr == true {
		go metrics.Log(metrics.DefaultRegistry, 10e9, log.New(os.Stderr, "metrics: ", log.Lmicroseconds))
	}

	if config.InfluxdbHost != "" &&
		config.InfluxdbDatabase != "" &&
		config.InfluxdbUser != "" &&
		config.InfluxdbPassword != "" {
		log.Println("fn=main metrics=influxdb")

		go influxdb.Influxdb(metrics.DefaultRegistry, 10e9, &influxdb.Config{
			Host:     config.InfluxdbHost,
			Database: config.InfluxdbDatabase,
			Username: config.InfluxdbUser,
			Password: config.InfluxdbPassword,
		})
	}

	connectToRedis(config)

	go runWebsocketHub(wsHub)
	go httpServer(config, wsHub)
	go udpServer(config.Port, toRecorder, toWebsocket)
	go websocketWriter(config, wsHub, toWebsocket)

	recorder := NewRecorder(client, config.Publish)
	go recordMeasurements(config, recorder, toRecorder)

	select {}
}
Пример #5
0
func initMetrics() {
	defReg := metrics.DefaultRegistry
	metricCurrentReqs = metrics.NewRegisteredCounter("curr_http_req", defReg)
	metricHttpReqRate = metrics.NewRegisteredMeter("http_req_rate", defReg)
	metricHttpReqTime = metrics.NewRegisteredTimer("http_req_time", defReg)
	metricsBackupTime = metrics.NewRegisteredTimer("backup_time", defReg)

	if !inProduction {
		logger.Notice("Librato stats disabled because not in production")
		return
	}
	if StringEmpty(config.LibratoToken) || StringEmpty(config.LibratoEmail) {
		logger.Notice("Librato stats disabled because no config.LibratoToken or no config.LibratoEmail")
		return
	}

	logger.Notice("Starting librato stats\n")
	go func() {
		librato.Librato(defReg, 1*time.Minute, *config.LibratoEmail, *config.LibratoToken, "blog", make([]float64, 0))
	}()
}
Пример #6
0
func main() {
	toRecorder := make(chan Measurement)

	if config.LibratoEmail != "" && config.LibratoToken != "" && config.LibratoSource != "" {
		log.Println("fn=main metircs=librato")
		go librato.Librato(metrics.DefaultRegistry,
			10e9,                  // interval
			config.LibratoEmail,   // account owner email address
			config.LibratoToken,   // Librato API token
			config.LibratoSource,  // source
			[]float64{50, 95, 99}, // precentiles to send
			time.Millisecond,      // time unit
		)
	}

	connectToRedis(config)

	go httpServer(config)
	go udpServer(config.Port, toRecorder)
	go recorder(config, toRecorder)

	select {}
}