metrics

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// DefaultRegisterer is a prometheus client registry that contains no
	// default metrics. See prometheus.Registry for more information.
	DefaultRegisterer prometheus.Registerer = defaultRegistry
	// DefaultGatherer points to the same registry as DefaultRegisterer.
	// See prometheus.Registry for more information.
	DefaultGatherer prometheus.Gatherer = defaultRegistry
)

Functions

func EnableGoRuntimeCollector added in v0.10.0

func EnableGoRuntimeCollector()

EnableGoRuntimeCollector enables the Prometheus Go runtime collector. Warning: This can have a serious impact on runtime performance. Enable at your own risk.

func MustRegister

func MustRegister(cs ...prometheus.Collector)

MustRegister registers the provided Collectors with the DefaultRegisterer and panics if any error occurs.

MustRegister is a shortcut for DefaultRegisterer.MustRegister(cs...). See there for more details.

func PromHandler

func PromHandler() http.Handler

PromHandler creates a prometheus HTTP handler that wraps DefaultGatherer and logs to the standard kvl logger.

func Register

func Register(c prometheus.Collector) error

Register registers the provided Collector with the DefaultRegisterer.

Register is a shortcut for DefaultRegisterer.Register(c). See there for more details.

Types

type Collector

type Collector interface {
	// ConnectionAdded notifies that a new downstream client connected.
	ConnectionAdded()
	// ConnectionRemoved notifies that a downstream client disconnected.
	ConnectionRemoved()
	// PacketReceived notifies that a packet was received.
	// TODO pass the endpoint here
	PacketReceived()
	// PacketSent notifies that a packet was sent.
	// TODO pass the endpoint here
	PacketSent()
	// PacketDropped notifies that a packet was dropped.
	// TODO pass the endpoint here
	PacketDropped()
	// SourceConnected notifies that upstream is live.
	SourceConnected()
	// SourceDisconnected notifies that upstream is offline.
	SourceDisconnected()
	// IsUpstreamConnected tells you if upstream is connected.
	IsUpstreamConnected() bool
	// StreamDuration reports how long a downstream connection was up
	StreamDuration(duration time.Duration)
}

Collector is the public face of a statistics collector. It is implemented by the individual stream stats.

type DummyCollector

type DummyCollector struct {
}

DummyCollector is placeholder for a real stats collector.

func (*DummyCollector) ConnectionAdded

func (stats *DummyCollector) ConnectionAdded()

func (*DummyCollector) ConnectionRemoved

func (stats *DummyCollector) ConnectionRemoved()

func (*DummyCollector) IsUpstreamConnected

func (stats *DummyCollector) IsUpstreamConnected() bool

func (*DummyCollector) PacketDropped

func (stats *DummyCollector) PacketDropped()

func (*DummyCollector) PacketReceived

func (stats *DummyCollector) PacketReceived()

func (*DummyCollector) PacketSent

func (stats *DummyCollector) PacketSent()

func (*DummyCollector) SourceConnected

func (stats *DummyCollector) SourceConnected()

func (*DummyCollector) SourceDisconnected

func (stats *DummyCollector) SourceDisconnected()

func (*DummyCollector) StreamDuration

func (stats *DummyCollector) StreamDuration(duration time.Duration)

type DummyStatistics

type DummyStatistics struct {
}

DummyStatistics is placeholder for a real stats handler.

func (*DummyStatistics) GetAllStreamStatistics

func (stats *DummyStatistics) GetAllStreamStatistics() map[string]*StreamStatistics

func (*DummyStatistics) GetGlobalStatistics

func (stats *DummyStatistics) GetGlobalStatistics() *StreamStatistics

func (*DummyStatistics) GetStreamStatistics

func (stats *DummyStatistics) GetStreamStatistics(name string) *StreamStatistics

func (*DummyStatistics) RegisterStream

func (stats *DummyStatistics) RegisterStream(name string) Collector

func (*DummyStatistics) RemoveStream

func (stats *DummyStatistics) RemoveStream(name string)

func (*DummyStatistics) Start

func (stats *DummyStatistics) Start()

func (*DummyStatistics) Stop

func (stats *DummyStatistics) Stop()

type Statistics

type Statistics interface {
	// Start starts the updater thread.
	Start()
	// Stop stops the updater thread.
	Stop()
	// RegisterStream adds a new stream to the map.
	// The name will be used as the lookup key.
	RegisterStream(name string) Collector
	// RemoveStream removes a stream from the map.
	RemoveStream(name string)
	// GetStreamStatistics fetches the statistics for a stream.
	// The returned object is a copy does not need to be handled with care.
	GetStreamStatistics(name string) *StreamStatistics
	// GetAllStreamStatistics fetches the statistics for all streams.
	// The returned object is a copy does not need to be handled with care.
	GetAllStreamStatistics() map[string]*StreamStatistics
	// GetGlobalStatistics fetches the global statistics.
	// The returned object is a copy does not need to be handled with care.
	GetGlobalStatistics() *StreamStatistics
}

Statistics is the access interface for a stat tracker. Streams update their state continuously, but data fields are only updated in periodic intervals. There is also an HTTP/JSON API facility available through the New...Api() methods in api.go.

func NewStatistics

func NewStatistics(maxconns uint, fullcons uint) Statistics

NewStatistics creates a new statistics container. You can start and stop the periodic updater using Start() and Stop(). Register your streams with RegisterStream(), this will return an updateable statistics object. You should not write to the individual fields directly, instead access them using the Add...() methods. Snapshots of the aggregated statistics can then be fetched with the Get...() methods.

type StreamStatistics

type StreamStatistics struct {
	Connections              int64
	MaxConnections           int64
	FullConnections          int64
	TotalPacketsReceived     uint64
	TotalPacketsSent         uint64
	TotalPacketsDropped      uint64
	TotalBytesReceived       uint64
	TotalBytesSent           uint64
	TotalBytesDropped        uint64
	TotalStreamTime          int64
	PacketsPerSecondReceived uint64
	PacketsPerSecondSent     uint64
	PacketsPerSecondDropped  uint64
	BytesPerSecondReceived   uint64
	BytesPerSecondSent       uint64
	BytesPerSecondDropped    uint64
	Connected                bool
}

StreamStatistics is the current state of a single stream or all streams combined.

Jump to

Keyboard shortcuts

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