-
Notifications
You must be signed in to change notification settings - Fork 619
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First stab at integrating raw statsd from #335
- Loading branch information
1 parent
806c4f0
commit 20fa958
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package statsdraw | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/alexcesaro/statsd" | ||
"github.com/fabiolb/fabio/metrics4" | ||
"github.com/fabiolb/fabio/metrics4/names" | ||
) | ||
|
||
type Provider struct { | ||
c *statsd.Client | ||
} | ||
|
||
func NewProvider(prefix, addr string, interval time.Duration) (*Provider, error) { | ||
opts := []statsd.Option{ | ||
statsd.Address(addr), | ||
statsd.FlushPeriod(interval), | ||
} | ||
if prefix != "" { | ||
opts = append(opts, statsd.Prefix(prefix)) | ||
} | ||
|
||
c, err := statsd.New(opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &Provider{c}, nil | ||
} | ||
|
||
func (p *Provider) NewCounter(name string, labels ...string) metrics4.Counter { | ||
return &Counter{c: p.c, name: name, labels: labels} | ||
} | ||
|
||
func (p *Provider) NewGauge(name string, labels ...string) metrics4.Gauge { | ||
return &Gauge{c: p.c, name: name, labels: labels} | ||
} | ||
|
||
func (p *Provider) NewTimer(name string, labels ...string) metrics4.Timer { | ||
return &Timer{c: p.c, name: name, labels: labels} | ||
} | ||
|
||
func (p *Provider) Unregister(interface{}) {} | ||
|
||
type Counter struct { | ||
c *statsd.Client | ||
name string | ||
labels []string | ||
} | ||
|
||
func (v *Counter) Count(n int) { | ||
v.c.Count(names.Flatten(v.name, v.labels, names.DotSeparator), n) | ||
} | ||
|
||
type Gauge struct { | ||
c *statsd.Client | ||
name string | ||
labels []string | ||
} | ||
|
||
func (v *Gauge) Update(n int) { | ||
v.c.Gauge(names.Flatten(v.name, v.labels, names.DotSeparator), n) | ||
} | ||
|
||
type Timer struct { | ||
c *statsd.Client | ||
name string | ||
labels []string | ||
} | ||
|
||
func (v *Timer) Update(d time.Duration) { | ||
v.c.Timing(names.Flatten(v.name, v.labels, names.DotSeparator), d) | ||
} |