1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-10-01 16:26:02 -04:00
v2fly/features/stats/stats.go

39 lines
1.1 KiB
Go
Raw Normal View History

package stats
import "v2ray.com/core/features"
2018-10-22 02:42:10 -04:00
// Counter is the interface for stats counters.
type Counter interface {
2018-10-22 02:42:10 -04:00
// Value is the current value of the counter.
Value() int64
2018-10-22 02:42:10 -04:00
// Set sets a new value to the counter, and returns the previous one.
Set(int64) int64
2018-10-22 02:42:10 -04:00
// Add adds a value to the current counter value, and returns the previous value.
Add(int64) int64
}
2018-10-22 02:42:10 -04:00
// Manager is the interface for stats manager.
type Manager interface {
features.Feature
2018-10-22 02:42:10 -04:00
// RegisterCounter registers a new counter to the manager. The identifier string must not be emtpy, and unique among other counters.
RegisterCounter(string) (Counter, error)
2018-10-22 02:42:10 -04:00
// GetCounter returns a counter by its identifier.
GetCounter(string) Counter
}
// GetOrRegisterCounter tries to get the StatCounter first. If not exist, it then tries to create a new counter.
func GetOrRegisterCounter(m Manager, name string) (Counter, error) {
counter := m.GetCounter(name)
if counter != nil {
return counter, nil
}
return m.RegisterCounter(name)
}
2018-10-12 17:57:56 -04:00
2018-10-13 09:15:49 -04:00
// ManagerType returns the type of Manager interface. Can be used to implement common.HasType.
2018-10-12 17:57:56 -04:00
func ManagerType() interface{} {
return (*Manager)(nil)
}