Example #1
0
func sendHistogramStats(metric string, value float64, additionalTag string, dog *statsd.Client) {
	tags := dog.Tags
	dog.Tags = append(dog.Tags, additionalTag)
	if os.Getenv("GOSHE_ADDITIONAL_TAGS") != "" {
		dog.Tags = append(dog.Tags, os.Getenv("GOSHE_ADDITIONAL_TAGS"))
	}
	dog.Histogram(metric, value, tags, 1)
	dog.Tags = tags
}
Example #2
0
File: ping.go Project: darron/goshe
func sendPingStats(dog *statsd.Client, rtt time.Duration) {
	var err error
	seconds := (float64(rtt) / 1000000000)
	address := strings.ToLower(strings.Replace(Endpoint, ".", "_", -1))
	metricName := fmt.Sprintf("ping.%s", address)
	err = dog.Histogram(metricName, seconds, dog.Tags, 1)
	if err != nil {
		Log(fmt.Sprintf("Error sending ping stats for '%s'", Endpoint), "info")
	}
}
Example #3
0
// InstrumentMiddleware collects metrics about the current request.
func InstrumentMiddleware(stats *statsd.Client) echo.MiddlewareFunc {
	return func(next echo.HandlerFunc) echo.HandlerFunc {
		return func(c echo.Context) error {
			defer func(start time.Time) {
				tags := []string{
					"method:" + c.Request().Method(),
					"status:" + strconv.Itoa(c.Response().Status()),
				}

				stats.Count("laika.request_total", 1, tags, 1)
				stats.Histogram("laika.request_duration_microseconds", float64(int(time.Since(start).Seconds()*1000000)), tags, 1)
			}(time.Now())

			return next(c)
		}
	}
}