stats

package
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: AGPL-3.0 Imports: 19 Imported by: 91

Documentation

Overview

Package stats provides functionality for instrumenting metrics and reporting them

The metrics can be user specified, or sourced from the runtime (reporters) To use this package correctly, you must instantiate exactly 1 output. If you use 0 outputs, certain metrics type will accumulate data unboundedly (e.g. histograms and meters) resulting in unreasonable memory usage. (though you can ignore this for shortlived processes, unit tests, etc) If you use >1 outputs, then each will only see a partial view of the stats. Currently supported outputs are DevNull and Graphite

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear()

func NewDevnull

func NewDevnull()

func WriteFloat64

func WriteFloat64(buf, prefix, name, suffix, tags []byte, val float64, now time.Time) []byte

Write* functions append a graphite metric line to the given buffer. `buf` is the incoming buffer to be appended to `prefix` is an optional prefix to the metric name which must have a trailing '.' if present `name` is the required name of the metric. It should not have a leading or trailing '.' or a trailing ';' `suffix` is an optional suffix to the metric name which must have a leading '.' if present. It should not have a trailing ';' `tags` is an optional list of tags which must have a leading ';' if present. `val` is the value of the metric `now` is the time that the metrics should be reported at returns `buf` with the new metric line appended

func WriteInt32 added in v0.12.0

func WriteInt32(buf, prefix, name, suffix, tags []byte, val int32, now time.Time) []byte

func WriteUint32

func WriteUint32(buf, prefix, name, suffix, tags []byte, val uint32, now time.Time) []byte

func WriteUint64

func WriteUint64(buf, prefix, name, suffix, tags []byte, val uint64, now time.Time) []byte

Types

type Bool

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

func NewBool

func NewBool(name string) *Bool

func NewBoolWithTags added in v1.0.0

func NewBoolWithTags(name, tags string) *Bool

func (*Bool) Peek added in v0.12.0

func (b *Bool) Peek() bool

func (*Bool) Set

func (b *Bool) Set(val bool)

func (*Bool) SetFalse

func (b *Bool) SetFalse()

func (*Bool) SetTrue

func (b *Bool) SetTrue()

func (*Bool) WriteGraphiteLine added in v1.0.0

func (b *Bool) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte

type Counter32

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

func NewCounter32

func NewCounter32(name string) *Counter32

func NewCounter32WithTags added in v1.0.0

func NewCounter32WithTags(name, tags string) *Counter32

func (*Counter32) Add

func (c *Counter32) Add(val int)

func (*Counter32) AddUint32

func (c *Counter32) AddUint32(val uint32)

func (*Counter32) Inc

func (c *Counter32) Inc()

func (*Counter32) Peek

func (c *Counter32) Peek() uint32

func (*Counter32) SetUint32

func (c *Counter32) SetUint32(val uint32)

func (*Counter32) WriteGraphiteLine added in v1.0.0

func (c *Counter32) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte

type Counter64

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

func NewCounter64

func NewCounter64(name string) *Counter64

func NewCounter64WithTags added in v1.0.0

func NewCounter64WithTags(name, tags string) *Counter64

func (*Counter64) AddUint64

func (c *Counter64) AddUint64(val uint64)

func (*Counter64) Inc

func (c *Counter64) Inc()

func (*Counter64) SetUint64

func (c *Counter64) SetUint64(val uint64)

func (*Counter64) WriteGraphiteLine added in v1.0.0

func (c *Counter64) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte

type CounterRate32

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

CounterRate32 publishes a counter32 as well as a rate32 in seconds

func NewCounterRate32

func NewCounterRate32(name string) *CounterRate32

func NewCounterRate32WithTags added in v1.0.0

func NewCounterRate32WithTags(name, tags string) *CounterRate32

func (*CounterRate32) Add

func (c *CounterRate32) Add(val int)

func (*CounterRate32) AddUint32

func (c *CounterRate32) AddUint32(val uint32)

func (*CounterRate32) Inc

func (c *CounterRate32) Inc()

func (*CounterRate32) Peek

func (c *CounterRate32) Peek() uint32

func (*CounterRate32) SetUint32

func (c *CounterRate32) SetUint32(val uint32)

func (*CounterRate32) WriteGraphiteLine added in v1.0.0

func (c *CounterRate32) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte

type Gauge32

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

func NewGauge32

func NewGauge32(name string) *Gauge32

func NewGauge32WithTags added in v1.0.0

func NewGauge32WithTags(name, tags string) *Gauge32

func (*Gauge32) Add

func (g *Gauge32) Add(val int)

func (*Gauge32) AddUint32

func (g *Gauge32) AddUint32(val uint32)

func (*Gauge32) Dec

func (g *Gauge32) Dec()

func (*Gauge32) DecUint32

func (g *Gauge32) DecUint32(val uint32)

func (*Gauge32) Inc

func (g *Gauge32) Inc()

func (*Gauge32) Set

func (g *Gauge32) Set(val int)

func (*Gauge32) SetUint32

func (g *Gauge32) SetUint32(val uint32)

func (*Gauge32) WriteGraphiteLine added in v1.0.0

func (g *Gauge32) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte

type Gauge64

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

func NewGauge64

func NewGauge64(name string) *Gauge64

func NewGauge64WithTags added in v1.0.0

func NewGauge64WithTags(name, tags string) *Gauge64

func (*Gauge64) Add

func (g *Gauge64) Add(val int)

func (*Gauge64) AddUint64

func (g *Gauge64) AddUint64(val uint64)

func (*Gauge64) Dec

func (g *Gauge64) Dec()

func (*Gauge64) DecUint64

func (g *Gauge64) DecUint64(val uint64)

func (*Gauge64) Inc

func (g *Gauge64) Inc()

func (*Gauge64) Peek

func (g *Gauge64) Peek() uint64

func (*Gauge64) Set

func (g *Gauge64) Set(val int)

func (*Gauge64) SetUint64

func (g *Gauge64) SetUint64(val uint64)

func (*Gauge64) WriteGraphiteLine added in v1.0.0

func (g *Gauge64) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte

type Graphite

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

func NewGraphite

func NewGraphite(prefix, addr string, interval, bufferSize int, timeout time.Duration) *Graphite

NewGraphite creates and starts a graphite reporter which. prefix is a string prefix which is added to every metric addr is the graphite address to report to interval is the interval in seconds that metrics should be reported. If interval is negative, metrics will not be reported automatically. bufferSize determines how many reporting intervals should be buffered in memory. If full, new intervals will not be reported timeout determines how long to wait while reporting an interval returns a new graphite instance which should only be used for manual reporting if interval is < 0

func (*Graphite) Report added in v1.0.0

func (g *Graphite) Report(now time.Time)

Report sends graphite metrics with the given timestamp. This should only be used if a negative reporting interval has been set.

type GraphiteMetric

type GraphiteMetric interface {
	// WriteGraphiteLine appends the Graphite formatted metric measurement to `buf` and resets measurements for the next interval if needed
	// `buf` is the incoming buffer to be appended to
	// `prefix` is an optional prefix to the metric name which must have a trailing '.' if present
	// `now` is the time that the metrics should be reported at
	WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte
}

type Kafka added in v0.12.0

type Kafka map[int32]*KafkaPartition

Kafka tracks the health of a consumer

func NewKafka added in v0.12.0

func NewKafka(prefix string, partitions []int32) Kafka

type KafkaPartition added in v0.12.0

type KafkaPartition struct {
	Offset   *Gauge64
	LogSize  *Gauge64
	Lag      *Gauge64
	Priority *Gauge64
	Ready    *Bool
}

KafkaPartition tracks the health of a partition consumer

func NewKafkaPartition added in v0.12.0

func NewKafkaPartition(prefix string) *KafkaPartition

type LatencyHistogram12h32

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

tracks latency measurements in a given range as 32 bit counters

func NewLatencyHistogram12h32

func NewLatencyHistogram12h32(name string) *LatencyHistogram12h32

func NewLatencyHistogram12h32WithTags added in v1.0.0

func NewLatencyHistogram12h32WithTags(name, tags string) *LatencyHistogram12h32

func (*LatencyHistogram12h32) Value

func (l *LatencyHistogram12h32) Value(t time.Duration)

func (*LatencyHistogram12h32) WriteGraphiteLine added in v1.0.0

func (l *LatencyHistogram12h32) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte

type LatencyHistogram15s32

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

tracks latency measurements in a given range as 32 bit counters

func NewLatencyHistogram15s32

func NewLatencyHistogram15s32(name string) *LatencyHistogram15s32

func NewLatencyHistogram15s32WithTags added in v1.0.0

func NewLatencyHistogram15s32WithTags(name, tags string) *LatencyHistogram15s32

func (*LatencyHistogram15s32) Value

func (l *LatencyHistogram15s32) Value(t time.Duration)

func (*LatencyHistogram15s32) WriteGraphiteLine added in v1.0.0

func (l *LatencyHistogram15s32) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte

type MemoryReporter

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

MemoryReporter sources memory stats from the runtime and reports them It also reports gcPercent based on the GOGC environment variable

func NewMemoryReporter

func NewMemoryReporter() *MemoryReporter

func (*MemoryReporter) WriteGraphiteLine added in v1.0.0

func (m *MemoryReporter) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte

type Meter32

type Meter32 struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewMeter32

func NewMeter32(name string, approx bool) *Meter32

func NewMeter32WithTags added in v1.0.0

func NewMeter32WithTags(name, tags string, approx bool) *Meter32

func (*Meter32) Value

func (m *Meter32) Value(val int)

func (*Meter32) ValueUint32

func (m *Meter32) ValueUint32(val uint32)

func (*Meter32) Values

func (m *Meter32) Values(val, num int)

func (*Meter32) ValuesUint32

func (m *Meter32) ValuesUint32(val, num uint32)

func (*Meter32) WriteGraphiteLine added in v1.0.0

func (m *Meter32) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte

type ProcessReporter

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

ProcessReporter sources stats from /proc

func NewProcessReporter

func NewProcessReporter() (*ProcessReporter, error)

func (*ProcessReporter) WriteGraphiteLine added in v1.0.0

func (m *ProcessReporter) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte

type Range32

type Range32 struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Range32 computes the min and max of sets of numbers, as 32bit numbers example application: queue depths min lets you see if the queue is able to drain max lets you see how large the queue tends to grow concurrency-safe

func NewRange32

func NewRange32(name string) *Range32

func NewRange32WithTags added in v1.0.0

func NewRange32WithTags(name, tags string) *Range32

func (*Range32) Value

func (r *Range32) Value(val int)

func (*Range32) ValueUint32

func (r *Range32) ValueUint32(val uint32)

func (*Range32) WriteGraphiteLine added in v1.0.0

func (r *Range32) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte

type Registry

type Registry struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Registry tracks metrics and reporters

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Clear

func (r *Registry) Clear()

type TimeDiffReporter32

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

reports the time in seconds until a specific timestamp is reached once reached, reports 0

func NewTimeDiffReporter32

func NewTimeDiffReporter32(name string, target uint32) *TimeDiffReporter32

func NewTimeDiffReporter32WithTags added in v1.0.0

func NewTimeDiffReporter32WithTags(name, tags string, target uint32) *TimeDiffReporter32

func (*TimeDiffReporter32) Set

func (g *TimeDiffReporter32) Set(target uint32)

func (*TimeDiffReporter32) WriteGraphiteLine added in v1.0.0

func (g *TimeDiffReporter32) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL