Add Metrics
This commit is contained in:
parent
4dc448056c
commit
8e97af8dc3
121 changed files with 8364 additions and 3811 deletions
44
vendor/github.com/go-kit/kit/metrics/dogstatsd/dogstatsd.go
generated
vendored
44
vendor/github.com/go-kit/kit/metrics/dogstatsd/dogstatsd.go
generated
vendored
|
@ -11,8 +11,10 @@
|
|||
package dogstatsd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
@ -72,7 +74,7 @@ func (d *Dogstatsd) NewCounter(name string, sampleRate float64) *Counter {
|
|||
d.rates.Set(name, sampleRate)
|
||||
return &Counter{
|
||||
name: name,
|
||||
obs: d.counters.Observe,
|
||||
obs: sampleObservations(d.counters.Observe, sampleRate),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +96,7 @@ func (d *Dogstatsd) NewTiming(name string, sampleRate float64) *Timing {
|
|||
d.rates.Set(name, sampleRate)
|
||||
return &Timing{
|
||||
name: name,
|
||||
obs: d.timings.Observe,
|
||||
obs: sampleObservations(d.timings.Observe, sampleRate),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,29 +106,34 @@ func (d *Dogstatsd) NewHistogram(name string, sampleRate float64) *Histogram {
|
|||
d.rates.Set(name, sampleRate)
|
||||
return &Histogram{
|
||||
name: name,
|
||||
obs: d.histograms.Observe,
|
||||
obs: sampleObservations(d.histograms.Observe, sampleRate),
|
||||
}
|
||||
}
|
||||
|
||||
// WriteLoop is a helper method that invokes WriteTo to the passed writer every
|
||||
// time the passed channel fires. This method blocks until the channel is
|
||||
// closed, so clients probably want to run it in its own goroutine. For typical
|
||||
// time the passed channel fires. This method blocks until ctx is canceled,
|
||||
// so clients probably want to run it in its own goroutine. For typical
|
||||
// usage, create a time.Ticker and pass its C channel to this method.
|
||||
func (d *Dogstatsd) WriteLoop(c <-chan time.Time, w io.Writer) {
|
||||
for range c {
|
||||
if _, err := d.WriteTo(w); err != nil {
|
||||
d.logger.Log("during", "WriteTo", "err", err)
|
||||
func (d *Dogstatsd) WriteLoop(ctx context.Context, c <-chan time.Time, w io.Writer) {
|
||||
for {
|
||||
select {
|
||||
case <-c:
|
||||
if _, err := d.WriteTo(w); err != nil {
|
||||
d.logger.Log("during", "WriteTo", "err", err)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SendLoop is a helper method that wraps WriteLoop, passing a managed
|
||||
// connection to the network and address. Like WriteLoop, this method blocks
|
||||
// until the channel is closed, so clients probably want to start it in its own
|
||||
// until ctx is canceled, so clients probably want to start it in its own
|
||||
// goroutine. For typical usage, create a time.Ticker and pass its C channel to
|
||||
// this method.
|
||||
func (d *Dogstatsd) SendLoop(c <-chan time.Time, network, address string) {
|
||||
d.WriteLoop(c, conn.NewDefaultManager(network, address, d.logger))
|
||||
func (d *Dogstatsd) SendLoop(ctx context.Context, c <-chan time.Time, network, address string) {
|
||||
d.WriteLoop(ctx, c, conn.NewDefaultManager(network, address, d.logger))
|
||||
}
|
||||
|
||||
// WriteTo flushes the buffered content of the metrics to the writer, in
|
||||
|
@ -233,6 +240,19 @@ func (d *Dogstatsd) tagValues(labelValues []string) string {
|
|||
|
||||
type observeFunc func(name string, lvs lv.LabelValues, value float64)
|
||||
|
||||
// sampleObservations returns a modified observeFunc that samples observations.
|
||||
func sampleObservations(obs observeFunc, sampleRate float64) observeFunc {
|
||||
if sampleRate >= 1 {
|
||||
return obs
|
||||
}
|
||||
return func(name string, lvs lv.LabelValues, value float64) {
|
||||
if rand.Float64() > sampleRate {
|
||||
return
|
||||
}
|
||||
obs(name, lvs, value)
|
||||
}
|
||||
}
|
||||
|
||||
// Counter is a DogStatsD counter. Observations are forwarded to a Dogstatsd
|
||||
// object, and aggregated (summed) per timeseries.
|
||||
type Counter struct {
|
||||
|
|
16
vendor/github.com/go-kit/kit/metrics/influx/influx.go
generated
vendored
16
vendor/github.com/go-kit/kit/metrics/influx/influx.go
generated
vendored
|
@ -4,9 +4,10 @@
|
|||
package influx
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
influxdb "github.com/influxdata/influxdb/client/v2"
|
||||
influxdb "github.com/influxdata/influxdb1-client/v2"
|
||||
|
||||
"github.com/go-kit/kit/log"
|
||||
"github.com/go-kit/kit/metrics"
|
||||
|
@ -88,10 +89,15 @@ type BatchPointsWriter interface {
|
|||
// time the passed channel fires. This method blocks until the channel is
|
||||
// closed, so clients probably want to run it in its own goroutine. For typical
|
||||
// usage, create a time.Ticker and pass its C channel to this method.
|
||||
func (in *Influx) WriteLoop(c <-chan time.Time, w BatchPointsWriter) {
|
||||
for range c {
|
||||
if err := in.WriteTo(w); err != nil {
|
||||
in.logger.Log("during", "WriteTo", "err", err)
|
||||
func (in *Influx) WriteLoop(ctx context.Context, c <-chan time.Time, w BatchPointsWriter) {
|
||||
for {
|
||||
select {
|
||||
case <-c:
|
||||
if err := in.WriteTo(w); err != nil {
|
||||
in.logger.Log("during", "WriteTo", "err", err)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
4
vendor/github.com/go-kit/kit/metrics/internal/lv/space.go
generated
vendored
4
vendor/github.com/go-kit/kit/metrics/internal/lv/space.go
generated
vendored
|
@ -79,7 +79,7 @@ type pair struct{ label, value string }
|
|||
func (n *node) observe(lvs LabelValues, value float64) {
|
||||
n.mtx.Lock()
|
||||
defer n.mtx.Unlock()
|
||||
if len(lvs) == 0 {
|
||||
if len(lvs) <= 0 {
|
||||
n.observations = append(n.observations, value)
|
||||
return
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ func (n *node) observe(lvs LabelValues, value float64) {
|
|||
func (n *node) add(lvs LabelValues, delta float64) {
|
||||
n.mtx.Lock()
|
||||
defer n.mtx.Unlock()
|
||||
if len(lvs) == 0 {
|
||||
if len(lvs) <= 0 {
|
||||
var value float64
|
||||
if len(n.observations) > 0 {
|
||||
value = last(n.observations) + delta
|
||||
|
|
24
vendor/github.com/go-kit/kit/metrics/statsd/statsd.go
generated
vendored
24
vendor/github.com/go-kit/kit/metrics/statsd/statsd.go
generated
vendored
|
@ -9,6 +9,7 @@
|
|||
package statsd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
@ -89,24 +90,29 @@ func (s *Statsd) NewTiming(name string, sampleRate float64) *Timing {
|
|||
}
|
||||
|
||||
// WriteLoop is a helper method that invokes WriteTo to the passed writer every
|
||||
// time the passed channel fires. This method blocks until the channel is
|
||||
// closed, so clients probably want to run it in its own goroutine. For typical
|
||||
// time the passed channel fires. This method blocks until ctx is canceled,
|
||||
// so clients probably want to run it in its own goroutine. For typical
|
||||
// usage, create a time.Ticker and pass its C channel to this method.
|
||||
func (s *Statsd) WriteLoop(c <-chan time.Time, w io.Writer) {
|
||||
for range c {
|
||||
if _, err := s.WriteTo(w); err != nil {
|
||||
s.logger.Log("during", "WriteTo", "err", err)
|
||||
func (s *Statsd) WriteLoop(ctx context.Context, c <-chan time.Time, w io.Writer) {
|
||||
for {
|
||||
select {
|
||||
case <-c:
|
||||
if _, err := s.WriteTo(w); err != nil {
|
||||
s.logger.Log("during", "WriteTo", "err", err)
|
||||
}
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SendLoop is a helper method that wraps WriteLoop, passing a managed
|
||||
// connection to the network and address. Like WriteLoop, this method blocks
|
||||
// until the channel is closed, so clients probably want to start it in its own
|
||||
// until ctx is canceled, so clients probably want to start it in its own
|
||||
// goroutine. For typical usage, create a time.Ticker and pass its C channel to
|
||||
// this method.
|
||||
func (s *Statsd) SendLoop(c <-chan time.Time, network, address string) {
|
||||
s.WriteLoop(c, conn.NewDefaultManager(network, address, s.logger))
|
||||
func (s *Statsd) SendLoop(ctx context.Context, c <-chan time.Time, network, address string) {
|
||||
s.WriteLoop(ctx, c, conn.NewDefaultManager(network, address, s.logger))
|
||||
}
|
||||
|
||||
// WriteTo flushes the buffered content of the metrics to the writer, in
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue