Documentation ¶
Index ¶
- func Count(name string, count int64, tags ...Tags)
- func SetDefaultStatser(s Statser)
- func Timing(name string, dur time.Duration, tags ...Tags)
- type Counter
- type Logger
- type MockStatser
- func (s *MockStatser) Count(name string, count int64, tags ...Tags)
- func (s *MockStatser) Timing(name string, dur time.Duration, tags ...Tags)
- func (s *MockStatser) WithPrefix(prefix string) Statser
- func (s *MockStatser) WithTag(tagKey, tagValue string) Statser
- func (s *MockStatser) WithTags(tags Tags) Statser
- type Statser
- func DefaultStatser() Statser
- func NewDatadogStatser(ddEndpoint string) (Statser, error)
- func NewInfluxDBStatser(client ifxdb.Client) Statser
- func NewNOOPStatser() Statser
- func WithLogger(statser Statser, logger Logger) Statser
- func WithPrefix(statser Statser, prefix string) Statser
- func WithSample(statser Statser, rate float64) Statser
- func WithTag(statser Statser, tagKey, tagValue string) Statser
- func WithTags(statser Statser, tags Tags) Statser
- type Tags
- type Timer
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefaultStatser ¶
func SetDefaultStatser(s Statser)
SetDefaultStatser sets the default statser
func Timing ¶
Timing submits a timing metric using the default statser
Example ¶
// suppose we have a Statser var s Statser = &MockStatser{} startTime := time.Now() // now Statser has WithPrefix, WithTags and WithTag and they all return Statser s = s.WithPrefix("api"). WithTags(Tags{ "route": "/ping", "status": "200", }). WithTag("env", "qa") // without tags s.Timing("request", time.Since(startTime)) // with tags s.Timing("request", time.Since(startTime), Tags{"i haz": "tagz"}) // also can do s.WithTag("i haz", "more tagz").Timing("request", time.Since(startTime))
Output:
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a wrapper around the Count method
func NewCounter ¶
NewCounter creats a new Counter
type Logger ¶ added in v1.0.7
type Logger interface {
Printf(format string, args ...interface{})
}
Logger is an interface for simple loggers It should be already satisfied by most common loggers
type MockStatser ¶
type MockStatser struct { TimingFn func(name string, dur time.Duration, tags ...Tags) CountFn func(name string, count int64, tags ...Tags) }
MockStatser is a mockable Statser
func (*MockStatser) Count ¶
func (s *MockStatser) Count(name string, count int64, tags ...Tags)
Count will call the underlying Count method
func (*MockStatser) Timing ¶
func (s *MockStatser) Timing(name string, dur time.Duration, tags ...Tags)
Timing will call the underlying Timing method
func (*MockStatser) WithPrefix ¶
func (s *MockStatser) WithPrefix(prefix string) Statser
func (*MockStatser) WithTag ¶
func (s *MockStatser) WithTag(tagKey, tagValue string) Statser
func (*MockStatser) WithTags ¶
func (s *MockStatser) WithTags(tags Tags) Statser
type Statser ¶
type Statser interface { // Timing submits a timing metric Timing(name string, dur time.Duration, tags ...Tags) // Count submits a count metric Count(name string, count int64, tags ...Tags) WithPrefix(prefix string) Statser WithTags(tags Tags) Statser WithTag(tagKey, tagValue string) Statser }
Statser can submit metrics
func DefaultStatser ¶
func DefaultStatser() Statser
DefaultStatser should return the currently set default statser
func NewDatadogStatser ¶
NewDatadogStatser creates a new Datadog Statser
func NewInfluxDBStatser ¶
NewInfluxDBStatser creates a new InfluxDB Statser
func NewNOOPStatser ¶
func NewNOOPStatser() Statser
NewNOOPStatser returns a statser that does nothing.
func WithLogger ¶ added in v1.0.7
WithLogger wraps an existing Statser so that stats get logged
func WithPrefix ¶
WithPrefix returns a new Statser with the given prefix applied to the name of the metrics E.g. WithPrefix(s, "prefix").Count("suffix", ...) will create a metric with name "prefix.suffix" WithPrefix can be called multiple times (See example in test code)
func WithSample ¶
WithSample returns a new Statser that samples stat submissions