//OutputMetricsIfRequired will send metrics to Graphite if a non-empty graphiteTCPAddress is passed in, or to the standard log if logMetrics is true.
// Make sure a sensible graphitePrefix that will uniquely identify your service is passed in, e.g. "content.test.people.rw.neo4j.ftaps58938-law1a-eu-t
func OutputMetricsIfRequired(graphiteTCPAddress string, graphitePrefix string, logMetrics bool) {
	if graphiteTCPAddress != "" {
		addr, _ := net.ResolveTCPAddr("tcp", graphiteTCPAddress)
		go graphite.Graphite(metrics.DefaultRegistry, 5*time.Second, graphitePrefix, addr)
	}
	if logMetrics { //useful locally
		//messy use of the 'standard' log package here as this method takes the log struct, not an interface, so can't use logrus.Logger
		go metrics.Log(metrics.DefaultRegistry, 60*time.Second, standardLog.New(os.Stdout, "metrics", standardLog.Lmicroseconds))
	}
}
Esempio n. 2
0
func startMetric() {
	ml, err := os.OpenFile(metricLog, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
	if err != nil {
		log.Fatal(err)
	}
	AddShutdownHook(func() {
		ml.Close()
	})

	go metrics.Log(metrics.DefaultRegistry, writeMetricLogInterval, log.New(ml, "", log.LstdFlags))
}
Esempio n. 3
0
func (p WOFPointInPolygon) SendMetricsTo(w io.Writer, d time.Duration, format string) bool {

	var r metrics.Registry
	r = *p.Metrics.Registry

	if format == "plain" {
		l := golog.New(w, "[pip-metrics] ", golog.Lmicroseconds)
		go metrics.Log(r, d, l)
		return true
	} else if format == "json" {
		go metrics.WriteJSON(r, d, w)
		return true
	} else {
		p.Logger.Warning("unable to send metrics anywhere, because what is '%s'", format)
		return false
	}
}
Esempio n. 4
0
func initStdout(interval time.Duration) error {
	logger := log.New(os.Stderr, "localhost: ", log.Lmicroseconds)
	go gometrics.Log(gometrics.DefaultRegistry, interval, logger)
	go gometrics.Log(ServiceRegistry, interval, logger)
	return nil
}
Esempio n. 5
0
// gmStdoutRegistry returns a go-metrics registry that reports to stdout.
func gmStdoutRegistry(interval time.Duration) (Registry, error) {
	logger := log.New(os.Stderr, "localhost: ", log.Lmicroseconds)
	r := gm.NewRegistry()
	go gm.Log(r, interval, logger)
	return &gmRegistry{r}, nil
}