本文整理汇总了Golang中github.com/DataDog/datadog-go/statsd.Client类的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SendLineStats
// 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: sendHistogramStats
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: sendQueriesStats
// 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: sendPingStats
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: InstrumentMiddleware
// 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: TailLog
// 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: runCommand
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")
}
}