WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# statsd

Statsd client which adheres to [statsd/client-interface](https://github.com/statsd/client-interface). A fork of github.com/cyberdelia/statsd.
Statsd client which adheres to
[statsd/client-interface](https://github.com/statsd/client-interface). A fork of
github.com/cyberdelia/statsd.
14 changes: 11 additions & 3 deletions statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package statsd
import (
"bufio"
"fmt"
. "github.com/visionmedia/go-debug"
"io"
"math/rand"
"net"
"sync"
"time"

. "github.com/visionmedia/go-debug"
)

var debug = Debug("statsd")
Expand Down Expand Up @@ -163,8 +164,15 @@ func (c *Client) Unique(name string, value int, rate float64) error {
return c.send(name, rate, "%d|s", value)
}

// Flush flushes writes any buffered data to the network.
// Flush flushes any buffered data to the network.
func (c *Client) Flush() error {
c.m.Lock()
defer c.m.Unlock()
return c.flush()
}

// flush() flushes data to the network. The caller is expected to hold c.m.
func (c *Client) flush() error {
return c.buf.Flush()
}

Expand Down Expand Up @@ -199,7 +207,7 @@ func (c *Client) send(stat string, rate float64, format string, args ...interfac

// Flush data if we have reach the buffer limit
if c.buf.Available() < len(format) {
if err := c.Flush(); err != nil {
if err := c.flush(); err != nil {
return nil
}
}
Expand Down