Codebase list golang-github-go-kit-kit / 0c02864
Document up an example of how to wire up a statsd connection. John Barton (joho) 8 years ago
1 changed file(s) with 26 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
5151 // handle request
5252 }
5353 ```
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 ```