gauge.go 293 B

123456789101112131415161718192021222324
  1. package metrics
  2. import "sync/atomic"
  3. type Gauge interface {
  4. Update(int64)
  5. Value() int64
  6. }
  7. type gauge struct {
  8. value int64
  9. }
  10. func NewGauge() Gauge {
  11. return &gauge{0}
  12. }
  13. func (g *gauge) Update(v int64) {
  14. atomic.AddInt64(&g.value, v)
  15. }
  16. func (g *gauge) Value() int64 {
  17. return g.value
  18. }