2014-04-13 07:59:40 +08:00
|
|
|
// Copyright (c) 2013 ActiveState Software Inc. All rights reserved.
|
|
|
|
|
2013-07-12 08:28:18 +08:00
|
|
|
package tail
|
|
|
|
|
|
|
|
// RateMonitor is a naive rate monitor that monitors the number of
|
|
|
|
// items processed in the current second.
|
|
|
|
type RateMonitor struct {
|
|
|
|
second int64
|
|
|
|
num int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RateMonitor) Tick(unixTime int64) int64 {
|
|
|
|
if r.second != unixTime {
|
|
|
|
r.second = unixTime
|
|
|
|
r.num = 1
|
|
|
|
} else {
|
|
|
|
r.num += 1
|
|
|
|
}
|
|
|
|
return r.num
|
|
|
|
}
|