Documentation
¶
Index ¶
- Variables
- func SetClock(c clock.Clock)
- type Meter
- type MeterRegistry
- func (r *MeterRegistry) Clear()
- func (r *MeterRegistry) FindIdle(since time.Time) []string
- func (r *MeterRegistry) ForEach(iterFunc func(string, *Meter))
- func (r *MeterRegistry) Get(name string) *Meter
- func (r *MeterRegistry) Remove(name string)
- func (r *MeterRegistry) TrimIdle(since time.Time) (trimmed int)
- type Snapshot
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var IdleTime = 20 * time.Second
IdleTime the time that need to pass scince last update before we declare a metere idle
Functions ¶
Types ¶
type Meter ¶
type Meter struct {
// contains filtered or unexported fields
}
Meter is a meter for monitoring a flow.
Example ¶
meter := new(Meter) t := time.NewTicker(100 * time.Millisecond) for i := 0; i < 100; i++ { <-t.C meter.Mark(30) } // Get the current rate. This will be accurate *now* but not after we // sleep (because we calculate it using EWMA). rate := meter.Snapshot().Rate // Sleep 2 seconds to allow the total to catch up. We snapshot every // second so the total may not yet be accurate. time.Sleep(2 * time.Second) // Get the current total. total := meter.Snapshot().Total fmt.Printf("%d (%d/s)\n", total, roundTens(rate))
Output: 3000 (300/s)
func NewMeter ¶
func NewMeter() *Meter
NewMeter returns a new Meter with the correct idle time.
While zero-value Meters can be used, their "last update" time will start at the program start instead of when the meter was created.
type MeterRegistry ¶
type MeterRegistry struct {
// contains filtered or unexported fields
}
MeterRegistry is a registry for named meters.
func (*MeterRegistry) Clear ¶
func (r *MeterRegistry) Clear()
Clear removes all meters from the registry.
func (*MeterRegistry) FindIdle ¶
func (r *MeterRegistry) FindIdle(since time.Time) []string
FindIdle finds all meters that haven't been used since the given time.
func (*MeterRegistry) ForEach ¶
func (r *MeterRegistry) ForEach(iterFunc func(string, *Meter))
ForEach calls the passed function for each registered meter.
func (*MeterRegistry) Get ¶
func (r *MeterRegistry) Get(name string) *Meter
Get gets (or creates) a meter by name.
func (*MeterRegistry) Remove ¶
func (r *MeterRegistry) Remove(name string)
Remove removes the named meter from the registry.
Note: The only reason to do this is to save a bit of memory. Unused meters don't consume any CPU (after they go idle).