stats

package
v1.0.1-0...-4cfcc0e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2026 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ManagerType

func ManagerType() interface{}

ManagerType returns the type of Manager interface. Can be used to implement common.HasType.

xray:api:stable

func SubscribeRunnableChannel

func SubscribeRunnableChannel(c Channel) (chan interface{}, error)

SubscribeRunnableChannel subscribes the channel and starts it if there is first subscriber coming.

func UnsubscribeClosableChannel

func UnsubscribeClosableChannel(c Channel, sub chan interface{}) error

UnsubscribeClosableChannel unsubscribes the channel and close it if there is no more subscriber.

Types

type Channel

type Channel interface {
	// Runnable implies that Channel is a runnable unit.
	common.Runnable
	// Publish broadcasts a message through the channel with a controlling context.
	Publish(context.Context, interface{})
	// Subscribers returns all subscribers.
	Subscribers() []chan interface{}
	// Subscribe registers for listening to channel stream and returns a new listener channel.
	Subscribe() (chan interface{}, error)
	// Unsubscribe unregisters a listener channel from current Channel object.
	Unsubscribe(chan interface{}) error
}

Channel is the interface for stats channel.

xray:api:stable

func GetOrRegisterChannel

func GetOrRegisterChannel(m Manager, name string) (Channel, error)

GetOrRegisterChannel tries to get the StatChannel first. If not exist, it then tries to create a new channel.

type Counter

type Counter interface {
	// Value is the current value of the counter.
	Value() int64
	// Set sets a new value to the counter, and returns the previous one.
	Set(int64) int64
	// Add adds a value to the current counter value, and returns the previous value.
	Add(int64) int64
}

Counter is the interface for stats counters.

xray:api:stable

func GetOrRegisterCounter

func GetOrRegisterCounter(m Manager, name string) (Counter, error)

GetOrRegisterCounter tries to get the StatCounter first. If not exist, it then tries to create a new counter.

type Manager

type Manager interface {
	features.Feature

	// RegisterCounter registers a new counter to the manager. The identifier string must not be empty, and unique among other counters.
	RegisterCounter(string) (Counter, error)
	// UnregisterCounter unregisters a counter from the manager by its identifier.
	UnregisterCounter(string) error
	// GetCounter returns a counter by its identifier.
	GetCounter(string) Counter
	// VisitCounters calls visitor on all managed counters.
	// The visitor runs under a read lock; it must not call RegisterCounter or UnregisterCounter (would deadlock).
	VisitCounters(func(string, Counter) bool)

	// RegisterOnlineMap registers a new OnlineMap to the manager. The identifier string must not be empty, and unique among other OnlineMaps.
	RegisterOnlineMap(string) (OnlineMap, error)
	// UnregisterOnlineMap unregisters an OnlineMap from the manager by its identifier.
	UnregisterOnlineMap(string) error
	// GetOnlineMap returns an OnlineMap by its identifier.
	GetOnlineMap(string) OnlineMap
	// VisitOnlineMaps calls visitor on all managed online maps.
	// The visitor runs under a read lock; it must not call RegisterOnlineMap or UnregisterOnlineMap (would deadlock).
	VisitOnlineMaps(func(string, OnlineMap) bool)

	// RegisterChannel registers a new channel to the manager. The identifier string must not be empty, and unique among other channels.
	RegisterChannel(string) (Channel, error)
	// UnregisterChannel unregisters a channel from the manager by its identifier.
	UnregisterChannel(string) error
	// GetChannel returns a channel by its identifier.
	GetChannel(string) Channel

	// GetAllOnlineUsers returns all online users from all OnlineMaps.
	GetAllOnlineUsers() []string
}

Manager is the interface for stats manager.

xray:api:stable

type NoopManager

type NoopManager struct{}

NoopManager is an implementation of Manager, which doesn't have actual functionality.

func (NoopManager) Close

func (NoopManager) Close() error

Close implements common.Closable.

func (NoopManager) GetAllOnlineUsers

func (NoopManager) GetAllOnlineUsers() []string

GetAllOnlineUsers implements Manager.

func (NoopManager) GetChannel

func (NoopManager) GetChannel(string) Channel

GetChannel implements Manager.

func (NoopManager) GetCounter

func (NoopManager) GetCounter(string) Counter

GetCounter implements Manager.

func (NoopManager) GetOnlineMap

func (NoopManager) GetOnlineMap(string) OnlineMap

GetOnlineMap implements Manager.

func (NoopManager) RegisterChannel

func (NoopManager) RegisterChannel(string) (Channel, error)

RegisterChannel implements Manager.

func (NoopManager) RegisterCounter

func (NoopManager) RegisterCounter(string) (Counter, error)

RegisterCounter implements Manager.

func (NoopManager) RegisterOnlineMap

func (NoopManager) RegisterOnlineMap(string) (OnlineMap, error)

RegisterOnlineMap implements Manager.

func (NoopManager) Start

func (NoopManager) Start() error

Start implements common.Runnable.

func (NoopManager) Type

func (NoopManager) Type() interface{}

Type implements common.HasType.

func (NoopManager) UnregisterChannel

func (NoopManager) UnregisterChannel(string) error

UnregisterChannel implements Manager.

func (NoopManager) UnregisterCounter

func (NoopManager) UnregisterCounter(string) error

UnregisterCounter implements Manager.

func (NoopManager) UnregisterOnlineMap

func (NoopManager) UnregisterOnlineMap(string) error

UnregisterOnlineMap implements Manager.

func (NoopManager) VisitCounters

func (NoopManager) VisitCounters(func(string, Counter) bool)

VisitCounters implements Manager.

func (NoopManager) VisitOnlineMaps

func (NoopManager) VisitOnlineMaps(func(string, OnlineMap) bool)

VisitOnlineMaps implements Manager.

type OnlineMap

type OnlineMap interface {
	// Count returns the number of unique online IPs.
	Count() int
	// AddIP increments the reference count for the given IP.
	AddIP(string)
	// RemoveIP decrements the reference count for the given IP. Deletes at zero.
	RemoveIP(string)
	// ForEach calls fn for each online IP with its last-seen Unix timestamp.
	// If fn returns false, iteration stops.
	// The callback must not call AddIP/RemoveIP on the same OnlineMap (would deadlock).
	ForEach(func(string, int64) bool)
}

OnlineMap is the interface for tracking online IP addresses.

xray:api:stable

func GetOrRegisterOnlineMap

func GetOrRegisterOnlineMap(m Manager, name string) (OnlineMap, error)

GetOrRegisterOnlineMap tries to get the OnlineMap first. If not exist, it then tries to create a new OnlineMap.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL