smira / go-statsd

Go statsd client library with zero allocation overhead, great performance and reconnects
MIT License
109 stars 18 forks source link

[STATSD] Error connecting to server: dial udp #23

Closed DonTermi closed 4 years ago

DonTermi commented 4 years ago

Hello,

with your statsd client I can't send metrics to any statsd server. In my case it's telegraf on localhost:2002. I'm using go 1.13.

I tested it from cmd line via

$ echo "foobar.test,region=eu:$(shuf -i 10-999 -n 1)|ms" | nc -w 1 -u localhost 2002

This works.

`> select * from "foobar.test" name: foobar.test time count host lower mean metric_type region stddev sum upper


2019-09-23T13:04:10Z 1 jenkinssol 733 733 timing eu 0 733 733`

What am I doing wrong?

My code

`package main

import ( "github.com/smira/go-statsd" )

func main() { client := statsd.NewClient("localhost:2002", statsd.MaxPacketSize(1400), statsd.MetricPrefix("foobar."))

start := time.Now()
client.Incr("requests.http", 1)
client.PrecisionTiming("requests.route.api.latency", time.Since(start))

client.Close()

}`

smira commented 4 years ago

Not sure, is there any error message or something?

You can try capturing the packets with nc (by running in server mode), but I don't see anything obvious.

DonTermi commented 4 years ago

It was working after adding

time.Sleep(time.Millisecond*50)

(after start := ...)

smira commented 4 years ago

Probably you have server starting up concurrently? In any case client reconnects automatically.