Documentation ¶
Overview ¶
Package statsd provides a StatsD client implementation that is safe for concurrent use by multiple goroutines and for efficiency can be created and reused.
Example usage:
// first create a client client, err := statsd.New("127.0.0.1:8125", "test-client") // handle any errors if err != nil { log.Fatal(err) } // make sure to clean up defer client.Close() // Send a stat err = client.Inc("stat1", 42, 1.0) // handle any errors if err != nil { log.Printf("Error sending metric: %+v", err) }
Index ¶
- Variables
- type Client
- func (s *Client) Close() error
- func (s *Client) Dec(stat string, value int64, rate float32) error
- func (s *Client) Gauge(stat string, value int64, rate float32) error
- func (s *Client) GaugeDelta(stat string, value int64, rate float32) error
- func (s *Client) Inc(stat string, value int64, rate float32) error
- func (s *Client) Raw(stat string, value string, rate float32) error
- func (s *Client) SetPrefix(prefix string)
- func (s *Client) Timing(stat string, delta int64, rate float32) error
- type NoopClient
- func (s *NoopClient) Close() error
- func (s *NoopClient) Dec(stat string, value int64, rate float32) error
- func (s *NoopClient) Gauge(stat string, value int64, rate float32) error
- func (s *NoopClient) GaugeDelta(stat string, value int64, rate float32) error
- func (s *NoopClient) Inc(stat string, value int64, rate float32) error
- func (s *NoopClient) Raw(stat string, value string, rate float32) error
- func (s *NoopClient) SetPrefix(prefix string)
- func (s *NoopClient) Timing(stat string, delta int64, rate float32) error
- type Statter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Dial = New
Compatibility alias
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Example ¶
// first create a client client, err := Dial("127.0.0.1:8125", "test-client") // handle any errors if err != nil { log.Fatal(err) } // make sure to clean up defer client.Close() // Send a stat err = client.Inc("stat1", 42, 1.0) // handle any errors if err != nil { log.Printf("Error sending metric: %+v", err) }
Output:
func New ¶
Returns a pointer to a new Client, and an error. addr is a string of the format "hostname:port", and must be parsable by net.ResolveUDPAddr. prefix is the statsd client prefix. Can be "" if no prefix is desired.
func (*Client) Dec ¶
Decrements a statsd count type. stat is a string name for the metric. value is the integer value. rate is the sample rate (0.0 to 1.0).
func (*Client) Gauge ¶
Submits/Updates a statsd gauge type. stat is a string name for the metric. value is the integer value. rate is the sample rate (0.0 to 1.0).
func (*Client) GaugeDelta ¶
Submits a delta to a statsd gauge. stat is the string name for the metric. value is the (positive or negative) change. rate is the sample rate (0.0 to 1.0).
func (*Client) Inc ¶
Increments a statsd count type. stat is a string name for the metric. value is the integer value rate is the sample rate (0.0 to 1.0)
func (*Client) Raw ¶
Raw formats the statsd event data, handles sampling, prepares it, and sends it to the server. stat is the string name for the metric. value is a preformatted "raw" value string. rate is the sample rate (0.0 to 1.0).
type NoopClient ¶
type NoopClient struct {
// contains filtered or unexported fields
}
Example ¶
// use interface so we can sub noop client if needed var client Statter var err error // first try to create a real client client, err = Dial("not-resolvable:8125", "test-client") // Lets say real client creation fails, but you don't care enough about // stats that you don't want your program to run. Just log an error and // make a NoopClient instead if err != nil { log.Println("Remote endpoint did not resolve. Disabling stats", err) client, err = NewNoop() } // make sure to clean up defer client.Close() // Send a stat err = client.Inc("stat1", 42, 1.0) // handle any errors if err != nil { log.Printf("Error sending metric: %+v", err) }
Output:
func NewNoop ¶
func NewNoop(a ...interface{}) (*NoopClient, error)
Returns a pointer to a new NoopClient, and an error (always nil, just supplied to support api convention). Use variadic arguments to support identical format as New, or a more conventional no argument form.
func (*NoopClient) Close ¶
func (s *NoopClient) Close() error
Close closes the connection and cleans up.
func (*NoopClient) Dec ¶
func (s *NoopClient) Dec(stat string, value int64, rate float32) error
Decrements a statsd count type. stat is a string name for the metric. value is the integer value. rate is the sample rate (0.0 to 1.0).
func (*NoopClient) Gauge ¶
func (s *NoopClient) Gauge(stat string, value int64, rate float32) error
Submits/Updates a statsd gauge type. stat is a string name for the metric. value is the integer value. rate is the sample rate (0.0 to 1.0).
func (*NoopClient) GaugeDelta ¶
func (s *NoopClient) GaugeDelta(stat string, value int64, rate float32) error
Submits a delta to a statsd gauge. stat is the string name for the metric. value is the (positive or negative) change. rate is the sample rate (0.0 to 1.0).
func (*NoopClient) Inc ¶
func (s *NoopClient) Inc(stat string, value int64, rate float32) error
Increments a statsd count type. stat is a string name for the metric. value is the integer value rate is the sample rate (0.0 to 1.0)
func (*NoopClient) Raw ¶
func (s *NoopClient) Raw(stat string, value string, rate float32) error
Raw formats the statsd event data, handles sampling, prepares it, and sends it to the server. stat is the string name for the metric. value is the preformatted "raw" value string. rate is the sample rate (0.0 to 1.0).
func (*NoopClient) SetPrefix ¶
func (s *NoopClient) SetPrefix(prefix string)
Sets/Updates the statsd client prefix
type Statter ¶
type Statter interface { Inc(stat string, value int64, rate float32) error Dec(stat string, value int64, rate float32) error Gauge(stat string, value int64, rate float32) error GaugeDelta(stat string, value int64, rate float32) error Timing(stat string, delta int64, rate float32) error Raw(stat string, value string, rate float32) error SetPrefix(prefix string) Close() error }