Document up an example of how to wire up a statsd connection.
John Barton (joho)
8 years ago
51 | 51 | // handle request |
52 | 52 | } |
53 | 53 | ``` |
54 | ||
55 | A gauge for the number of goroutines currently running, exported via statsd. | |
56 | ```go | |
57 | import ( | |
58 | "net" | |
59 | "os" | |
60 | "runtime" | |
61 | "time" | |
62 | ||
63 | "github.com/go-kit/kit/metrics/statsd" | |
64 | ) | |
65 | ||
66 | func main() { | |
67 | statsdWriter, err := net.Dial("udp", "127.0.0.1:8126") | |
68 | if err != nil { | |
69 | os.Exit(1) | |
70 | } | |
71 | ||
72 | reportingDuration := 5 * time.Second | |
73 | goroutines := statsd.NewGauge(statsdWriter, "total_goroutines", reportingDuration) | |
74 | for range time.Tick(reportingDuration) { | |
75 | goroutines.Set(float64(runtime.NumGoroutine())) | |
76 | } | |
77 | } | |
78 | ||
79 | ``` |