in memory stats buffer

This commit is contained in:
Asim Aslam 2019-12-05 00:08:46 +00:00
parent 40c09eed1c
commit af3d4e595f

38
debug/stats/default.go Normal file
View File

@ -0,0 +1,38 @@
package stats
import (
"github.com/micro/go-micro/debug/buffer"
)
type stats struct {
buffer *buffer.Buffer
}
func (s *stats) Read() ([]*Stat, error) {
// TODO adjustable size and optional read values
buf := s.buffer.Get(1)
var stats []*Stat
for _, b := range buf {
stat, ok := b.Value.(*Stat)
if !ok {
continue
}
stats = append(stats, stat)
}
return stats, nil
}
func (s *stats) Write(stat *Stat) error {
s.buffer.Put(stat)
return nil
}
// NewStats returns a new in memory stats buffer
// TODO add options
func NewStats() Stats {
return &stats{
buffer: buffer.New(1024),
}
}