Skip to content

Commit

Permalink
Merge pull request #1 from stevenh/gauge-relative
Browse files Browse the repository at this point in the history
Add GaugeRelative to support Telegraf statsd implementation
  • Loading branch information
stevenh authored Jan 30, 2017
2 parents 7fea3f0 + 23802da commit 6444453
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package statsd

import (
"fmt"
"io"
"math/rand"
"net"
Expand Down Expand Up @@ -93,6 +94,20 @@ func (c *conn) metric(prefix, bucket string, n interface{}, typ string, rate flo
c.mu.Unlock()
}

func (c *conn) gaugeRelative(prefix, bucket string, value interface{}, tags string) {
c.mu.Lock()
l := len(c.buf)
c.appendBucket(prefix, bucket, tags)
if isNegative(value) {
c.appendNumber(value)
} else {
c.appendString(fmt.Sprintf("+%v", value))
}
c.appendType("g")
c.flushIfBufferFull(l)
c.mu.Unlock()
}

func (c *conn) gauge(prefix, bucket string, value interface{}, tags string) {
c.mu.Lock()
l := len(c.buf)
Expand Down
8 changes: 8 additions & 0 deletions statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ func (c *Client) Gauge(bucket string, value interface{}) {
c.conn.gauge(c.prefix, bucket, value, c.tags)
}

// GaugeRelative records an relative value for the given bucket.
func (c *Client) GaugeRelative(bucket string, value interface{}) {
if c.skip() {
return
}
c.conn.gaugeRelative(c.prefix, bucket, value, c.tags)
}

// Timing sends a timing value to a bucket.
func (c *Client) Timing(bucket string, value interface{}) {
if c.skip() {
Expand Down

0 comments on commit 6444453

Please sign in to comment.