metrics

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDuration

func FormatDuration(ts time.Duration) string

Types

type Counter

type Counter interface {
	Add(unit int)
	Reset()

	Count() int
	GetStarttime() time.Time
}

Counter providers a threadsafe counter to use for storing long running counts

func NewCounter

func NewCounter() Counter

NewCounter initializes a counter starting at time.Now() and a count of 0 and returns it

type MessageCountFn

type MessageCountFn func() int

type MonitorAccumulation

type MonitorAccumulation int

MonitorAccumulation controls how monitor data is accumulated over time into larger summary buckets

const (
	// Cumulative values with sum over time
	Cumulative MonitorAccumulation = iota
	// Average values will average over time
	Average
)

type MonitorHistory

type MonitorHistory interface {
	Start()
	Stop()

	Minutes() []float64
	Hours() []float64
	Days() []float64
	Weeks() []float64
	Months() []float64

	Report(w *bufio.Writer)
}

MonitorHistory runs a monitor every minute and rotates and averages the results out across time

func NewMonitorHistory

func NewMonitorHistory(t MonitorType, a MonitorAccumulation, monitor func() float64) MonitorHistory

NewMonitorHistory returns a new MonitorHistory with starttime of time.Now and Started running with supplied monitor

type MonitorType

type MonitorType int

MonitorType controls how the monitor will report itself

const (
	// Count indicates the monitor should report in interger format
	Count MonitorType = iota
	// Percent indicates the monitor should report in decimal format with 2 places
	Percent
	// MegaBytes indicates the monitor should transform the raw number into MBs
	MegaBytes
)

type Monitors

type Monitors struct {
	MessageCounter Counter
	Messages       MonitorHistory
	Memory         MonitorHistory
	ClientConns    MonitorHistory
	// contains filtered or unexported fields
}

Monitors is a package of metrics for a Cwtch Server including message count, CPU, Mem, and conns

func (*Monitors) Start

func (mp *Monitors) Start(ts tapir.Service, mcfn MessageCountFn, configDir string, doLogging bool)

Start initializes a Monitors's monitors

func (*Monitors) Stop

func (mp *Monitors) Stop()

Stop stops all the monitors in a Monitors

Jump to

Keyboard shortcuts

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