示例#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
// 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
}
示例#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)
		}
	}
}
示例#4
0
文件: tail.go 项目: darron/goshe
// 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)
		}
	}
}
示例#5
0
文件: tail.go 项目: darron/goshe
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")
	}
}