flow

package module
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: MIT Imports: 6 Imported by: 1

README

go-flow-metrics

Travis CI Discourse posts

A simple library for tracking flow metrics.

A simple alternative to rcrowley's go-metrics that's a lot faster (and only does simple bandwidth metrics).

Table of Contents

Install

make install

Contribute

PRs are welcome!

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © Protocol Labs


The last gx published version of this module was: 0.2.0: QmQFXpvKpF34dK9HcE7k8Ksk8V4BwWYZtdEcjzu5aUgRVr

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IdleRate = 1e-13

IdleRate the rate at which we declare a meter idle (and stop tracking it until it's re-registered).

The default ensures that 1 event every ~30s will keep the meter from going idle.

Functions

func SetClock

func SetClock(c clock.Clock)

SetClock sets a clock to use in the sweeper. This will probably only ever be useful for testing purposes.

Types

type Meter

type Meter struct {
	// contains filtered or unexported fields
}

Meter is a meter for monitoring a flow.

func (*Meter) IsIdle

func (m *Meter) IsIdle() bool

func (*Meter) Mark

func (m *Meter) Mark(count uint64)

Mark updates the total.

func (*Meter) Reset

func (m *Meter) Reset()

Reset sets accumulator, total and rate to zero.

func (*Meter) SetActive

func (m *Meter) SetActive()

func (*Meter) SetIdle

func (m *Meter) SetIdle()

func (*Meter) Snapshot

func (m *Meter) Snapshot() Snapshot

Snapshot gets a snapshot of the total and rate.

func (*Meter) String

func (m *Meter) String() string

func (*Meter) Update

func (m *Meter) Update(tdiff time.Duration)

type MeterInterface

type MeterInterface interface {
	String() string
	Mark(count uint64)
	Snapshot() Snapshot
	Reset()
	Update(tdiff time.Duration)
	IsIdle() bool
	SetIdle()
	SetActive()
}

func NewMeter

func NewMeter() MeterInterface

NewMeter returns a new Meter with the correct idle time.

While zero-value Meters can be used, their "last update" time will start at the program start instead of when the meter was created.

type MeterRegistry

type MeterRegistry struct {
	// contains filtered or unexported fields
}

MeterRegistry is a registry for named meters.

func (*MeterRegistry) Clear

func (r *MeterRegistry) Clear()

Clear removes all meters from the registry.

func (*MeterRegistry) FindIdle

func (r *MeterRegistry) FindIdle(since time.Time) []string

FindIdle finds all meters that haven't been used since the given time.

func (*MeterRegistry) ForEach

func (r *MeterRegistry) ForEach(iterFunc interface{})

ForEach calls the passed function for each registered meter.

Note: switch was added for compatibility reasons

func (*MeterRegistry) Get

func (r *MeterRegistry) Get(name string) MeterInterface

Get gets (or creates) a meter by name.

func (*MeterRegistry) Remove

func (r *MeterRegistry) Remove(name string)

Remove removes the named meter from the registry.

Note: The only reason to do this is to save a bit of memory. Unused meters don't consume any CPU (after they go idle).

func (*MeterRegistry) TrimIdle

func (r *MeterRegistry) TrimIdle(since time.Time) (trimmed int)

TrimIdle trims that haven't been updated since the given time. Returns the number of timers trimmed.

type Snapshot

type Snapshot struct {
	Rate       float64
	Total      uint64
	LastUpdate time.Time
}

Snapshot is a rate/total snapshot.

func (Snapshot) String

func (s Snapshot) String() string

type SweeperInterface

type SweeperInterface interface {
	Register(m MeterInterface)
}

Jump to

Keyboard shortcuts

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