Пример #1
0
// SendLineStats sends the stats to Datadog.
func SendLineStats(dog *statsd.Client, line string, metric string) {
	Log(fmt.Sprintf("%s: %s", metric, line), "debug")
	oldTags := dog.Tags
	dog.Tags = append(dog.Tags, fmt.Sprintf("record:%s", metric))
	dog.Count("dnsmasq.event", 1, dog.Tags, 1)
	dog.Tags = oldTags
}
Пример #2
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
}
Пример #3
0
// sendQueriesStats actually sends the stats to Dogstatsd.
func sendQueriesStats(metric string, value int64, 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.Count(metric, value, tags, signalInterval)
	dog.Tags = tags
}
Пример #4
0
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")
	}
}
Пример #5
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)
		}
	}
}
Пример #6
0
// TailLog tails a file and sends stats to Datadog.
func TailLog(t *tail.Tail, dog *statsd.Client, r *regexp.Regexp) {
	for line := range t.Lines {
		// Blank lines really mess this up - this protects against it.
		if line.Text == "" {
			continue
		}
		match := r.FindAllStringSubmatch(line.Text, -1)
		if match != nil {
			Log(fmt.Sprintf("Match: %s", match), "debug")
			Log(fmt.Sprintf("Sending Stat: %s", MetricName), "debug")
			tags := dog.Tags
			if MetricTag != "" {
				tags = append(tags, MetricTag)
			}
			dog.Count(MetricName, 1, tags, 1)
		}
	}
}
Пример #7
0
func runCommand(cli string, args []string, r *regexp.Regexp, dog *statsd.Client) {
	cmd := exec.Command(cli, args...)
	cmdReader, err := cmd.StdoutPipe()
	if err != nil {
		Log(fmt.Sprintf("There was an error running '%s': %s", ProgramStdout, err), "info")
		os.Exit(1)
	}
	scanner := bufio.NewScanner(cmdReader)
	go func() {
		for scanner.Scan() {
			line := scanner.Text()
			Log(fmt.Sprintf("Line: %s", line), "debug")
			// Blank lines are bad for the matching software - it freaks out.
			if line == "" {
				continue
			}
			match := r.FindAllStringSubmatch(line, -1)
			if match != nil {
				Log(fmt.Sprintf("Match: %s", match), "debug")
				Log(fmt.Sprintf("Sending Stat: %s", MetricName), "debug")
				tags := dog.Tags
				if MetricTag != "" {
					tags = append(tags, MetricTag)
				}
				dog.Count(MetricName, 1, tags, 1)
			}
		}
	}()

	err = cmd.Start()
	if err != nil {
		Log("There was and error starting the command.", "info")
	}

	err = cmd.Wait()
	if err != nil {
		Log("There was and error waiting for the command.", "info")
	}
}