Skip to content

pnelson/metrics

Repository files navigation

metrics

Package metrics aggregates metrics over regular intervals.

Usage

Initialize a new metrics instance with 10 second aggregated intervals over a 1 hour window. Optionally emit runtime stats.

m := metrics.New(time.Hour, 10*time.Second)
go m.MemStats(time.Second)

Use Add for monotonically increasing Counter values such as errors or execution counts.

m.Add([]string{"errors"}, 1)

Use Set for measured Gauge values such as memory usage or active requests.

var n uint64
m.Set([]string{"active"}, float64(atomic.AddUint64(&n, 1)))
defer func() { m.Set([]string{"active"}, float64(atomic.AddUint64(&n, ^uint64(0)))) }()

Use Mod to simplify a Gauge that increments or decrements like the above. The gauge will increment or decrement from zero if there is no previous value within the entire stored window.

m.Mod([]string{"active"}, 1)
defer m.Mod([]string{"active"}, -1)

Use Put for sample values distributed over the Histogram bucket values such as latency. The Histogram also stores a count of the samples.

m.Put([]string{"latency"}, 1)

Use Timer as a shorthand for Put to sample the duration elapsed in milliseconds from a starting time.Time value.

func (m *M) Method() {
  defer m.Timer([]string{"method", "latency"}, time.Now())
  // ...
}

About

Package metrics aggregates metrics over regular intervals.

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages