flow

package
v0.0.0-...-8b9b725 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2019 License: MIT Imports: 5 Imported by: 4

README

go-flow-metrics

Travis CI

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

Documentation

Index

Examples

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

This section is empty.

Types

type Meter

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

Meter is a meter for monitoring a flow.

Example
meter := new(Meter)
t := time.NewTicker(100 * time.Millisecond)
for i := 0; i < 100; i++ {
	<-t.C
	meter.Mark(30)
}

// Get the current rate. This will be accurate *now* but not after we
// sleep (because we calculate it using EWMA).
rate := meter.Snapshot().Rate

// Sleep 2 seconds to allow the total to catch up. We snapshot every
// second so the total may not yet be accurate.
time.Sleep(2 * time.Second)

// Get the current total.
total := meter.Snapshot().Total

fmt.Printf("%d (%d/s)\n", total, int64(math.Round(float64(rate)/10)))
Output:

3000 (300/s)

func (*Meter) Mark

func (m *Meter) Mark(count uint64)

Mark updates the total.

func (*Meter) Snapshot

func (m *Meter) Snapshot() Snapshot

Snapshot gets a consistent snapshot of the total and rate.

func (*Meter) String

func (m *Meter) String() string

type MeterRegistry

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

MeterRegistry is a registry for named meters.

func (*MeterRegistry) ForEach

func (r *MeterRegistry) ForEach(iterFunc func(string, *Meter))

ForEach calls the passed function for each registered meter.

func (*MeterRegistry) Get

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

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).

type Snapshot

type Snapshot struct {
	Rate  float64
	Total uint64
}

Snapshot is a rate/total snapshot.

func (Snapshot) String

func (s Snapshot) String() string

Jump to

Keyboard shortcuts

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