Skip to content

Commit

Permalink
metrics: add raw statsd reporter
Browse files Browse the repository at this point in the history
This patch adds a statds reporter which does not aggregate values.

Fixes #327
  • Loading branch information
magiconair committed Aug 6, 2017
1 parent 51f2c8f commit d6c62e7
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 4 deletions.
9 changes: 5 additions & 4 deletions fabio.properties
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,11 @@
#
# Possible values are:
# <empty>: do not report metrics
# stdout: report metrics to stdout
# graphite: report metrics to Graphite on ${metrics.graphite.addr}
# statsd: report metrics to StatsD on ${metrics.statsd.addr}
# circonus: report metrics to Circonus (http://circonus.com/)
# stdout: report metrics to stdout
# graphite: report metrics to Graphite on ${metrics.graphite.addr}
# statsd: report metrics to StatsD on ${metrics.statsd.addr}
# statsd_raw: report metrics to StatsD on ${metrics.statsd.addr} without aggregation
# circonus: report metrics to Circonus (http://circonus.com/)
#
# The default is
#
Expand Down
4 changes: 4 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func NewRegistry(cfg config.Metrics) (r Registry, err error) {
log.Printf("[INFO] Sending metrics to StatsD on %s as %q", cfg.StatsDAddr, prefix)
return gmStatsDRegistry(prefix, cfg.StatsDAddr, cfg.Interval)

case "statsd_raw":
log.Printf("[INFO] Sending metrics to StatsD (raw) on %s as %q", cfg.StatsDAddr, prefix)
return newRawStatsDRegistry(prefix, cfg.StatsDAddr, cfg.Interval)

case "circonus":
return circonusRegistry(prefix, cfg.Circonus, cfg.Interval)

Expand Down
63 changes: 63 additions & 0 deletions metrics/statsd_raw.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package metrics

import (
"errors"
"fmt"
"time"

alstatsd "github.com/alexcesaro/statsd"
)

func newRawStatsDRegistry(prefix, addr string, interval time.Duration) (Registry, error) {
if addr == "" {
return nil, errors.New(" statsd addr missing")
}

c, err := alstatsd.New(alstatsd.Address(addr), alstatsd.FlushPeriod(interval))
if err != nil {
return nil, fmt.Errorf(" cannot init statsd client: %s", err)
}

return &rawStatsDRegistry{c}, nil
}

type rawStatsDRegistry struct {
c *alstatsd.Client
}

func (r *rawStatsDRegistry) Names() []string { return nil }
func (r *rawStatsDRegistry) Unregister(name string) {}
func (r *rawStatsDRegistry) UnregisterAll() {}

func (r *rawStatsDRegistry) GetCounter(name string) Counter {
return &rawStatsDCounter{r.c, name}
}

func (r *rawStatsDRegistry) GetTimer(name string) Timer {
return &rawStatsDTimer{r.c, name}
}

type rawStatsDCounter struct {
c *alstatsd.Client
name string
}

func (c *rawStatsDCounter) Inc(n int64) {
c.c.Increment(c.name)
}

type rawStatsDTimer struct {
c *alstatsd.Client
name string
}

func (t *rawStatsDTimer) Update(d time.Duration) {
t.c.Timing(t.name, int(d/time.Millisecond))
}

func (t *rawStatsDTimer) UpdateSince(start time.Time) {
t.Update(time.Now().Sub(start))
}

func (t *rawStatsDTimer) Rate1() float64 { return 0 }
func (t *rawStatsDTimer) Percentile(nth float64) float64 { return 0 }

0 comments on commit d6c62e7

Please sign in to comment.