github.com/nsqio/nsq@v1.3.0/internal/statsd/client.go (about) 1 package statsd 2 3 import ( 4 "fmt" 5 "io" 6 ) 7 8 type Client struct { 9 w io.Writer 10 prefix string 11 } 12 13 func NewClient(w io.Writer, prefix string) *Client { 14 return &Client{ 15 w: w, 16 prefix: prefix, 17 } 18 } 19 20 func (c *Client) Incr(stat string, count int64) error { 21 return c.send(stat, "%d|c", count) 22 } 23 24 func (c *Client) Decr(stat string, count int64) error { 25 return c.send(stat, "%d|c", -count) 26 } 27 28 func (c *Client) Timing(stat string, delta int64) error { 29 return c.send(stat, "%d|ms", delta) 30 } 31 32 func (c *Client) Gauge(stat string, value int64) error { 33 return c.send(stat, "%d|g", value) 34 } 35 36 func (c *Client) send(stat string, format string, value int64) error { 37 format = fmt.Sprintf("%s%s:%s\n", c.prefix, stat, format) 38 _, err := fmt.Fprintf(c.w, format, value) 39 return err 40 }