metrictank: github.com/grafana/metrictank/stats Index | Files | Directories

package stats

import "github.com/grafana/metrictank/stats"

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

Package Files

bool.go counter32.go counter64.go counterrate32.go gauge32.go gauge64.go init.go kafka.go latencyhistogram12h32.go latencyhistogram15s32.go memory_reporter.go meter32.go out_devnull.go out_graphite.go process_reporter.go range32.go registry.go timediff_reporter.go write.go

func Clear Uses

func Clear()

func NewDevnull Uses

func NewDevnull()

func WriteFloat64 Uses

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 Uses

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

func WriteUint32 Uses

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

func WriteUint64 Uses

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

type Bool Uses

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

func NewBool Uses

func NewBool(name string) *Bool

func NewBoolWithTags Uses

func NewBoolWithTags(name, tags string) *Bool

func (*Bool) Peek Uses

func (b *Bool) Peek() bool

func (*Bool) Set Uses

func (b *Bool) Set(val bool)

func (*Bool) SetFalse Uses

func (b *Bool) SetFalse()

func (*Bool) SetTrue Uses

func (b *Bool) SetTrue()

func (*Bool) WriteGraphiteLine Uses

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

type Counter32 Uses

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

func NewCounter32 Uses

func NewCounter32(name string) *Counter32

func NewCounter32WithTags Uses

func NewCounter32WithTags(name, tags string) *Counter32

func (*Counter32) Add Uses

func (c *Counter32) Add(val int)

func (*Counter32) AddUint32 Uses

func (c *Counter32) AddUint32(val uint32)

func (*Counter32) Inc Uses

func (c *Counter32) Inc()

func (*Counter32) Peek Uses

func (c *Counter32) Peek() uint32

func (*Counter32) SetUint32 Uses

func (c *Counter32) SetUint32(val uint32)

func (*Counter32) WriteGraphiteLine Uses

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

type Counter64 Uses

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

func NewCounter64 Uses

func NewCounter64(name string) *Counter64

func NewCounter64WithTags Uses

func NewCounter64WithTags(name, tags string) *Counter64

func (*Counter64) AddUint64 Uses

func (c *Counter64) AddUint64(val uint64)

func (*Counter64) Inc Uses

func (c *Counter64) Inc()

func (*Counter64) SetUint64 Uses

func (c *Counter64) SetUint64(val uint64)

func (*Counter64) WriteGraphiteLine Uses

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

type CounterRate32 Uses

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

CounterRate32 publishes a counter32 as well as a rate32 in seconds

func NewCounterRate32 Uses

func NewCounterRate32(name string) *CounterRate32

func NewCounterRate32WithTags Uses

func NewCounterRate32WithTags(name, tags string) *CounterRate32

func (*CounterRate32) Add Uses

func (c *CounterRate32) Add(val int)

func (*CounterRate32) AddUint32 Uses

func (c *CounterRate32) AddUint32(val uint32)

func (*CounterRate32) Inc Uses

func (c *CounterRate32) Inc()

func (*CounterRate32) Peek Uses

func (c *CounterRate32) Peek() uint32

func (*CounterRate32) SetUint32 Uses

func (c *CounterRate32) SetUint32(val uint32)

func (*CounterRate32) WriteGraphiteLine Uses

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

type Gauge32 Uses

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

func NewGauge32 Uses

func NewGauge32(name string) *Gauge32

func NewGauge32WithTags Uses

func NewGauge32WithTags(name, tags string) *Gauge32

func (*Gauge32) Add Uses

func (g *Gauge32) Add(val int)

func (*Gauge32) AddUint32 Uses

func (g *Gauge32) AddUint32(val uint32)

func (*Gauge32) Dec Uses

func (g *Gauge32) Dec()

func (*Gauge32) DecUint32 Uses

func (g *Gauge32) DecUint32(val uint32)

func (*Gauge32) Inc Uses

func (g *Gauge32) Inc()

func (*Gauge32) Set Uses

func (g *Gauge32) Set(val int)

func (*Gauge32) SetUint32 Uses

func (g *Gauge32) SetUint32(val uint32)

func (*Gauge32) WriteGraphiteLine Uses

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

type Gauge64 Uses

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

func NewGauge64 Uses

func NewGauge64(name string) *Gauge64

func NewGauge64WithTags Uses

func NewGauge64WithTags(name, tags string) *Gauge64

func (*Gauge64) Add Uses

func (g *Gauge64) Add(val int)

func (*Gauge64) AddUint64 Uses

func (g *Gauge64) AddUint64(val uint64)

func (*Gauge64) Dec Uses

func (g *Gauge64) Dec()

func (*Gauge64) DecUint64 Uses

func (g *Gauge64) DecUint64(val uint64)

func (*Gauge64) Inc Uses

func (g *Gauge64) Inc()

func (*Gauge64) Peek Uses

func (g *Gauge64) Peek() uint64

func (*Gauge64) Set Uses

func (g *Gauge64) Set(val int)

func (*Gauge64) SetUint64 Uses

func (g *Gauge64) SetUint64(val uint64)

func (*Gauge64) WriteGraphiteLine Uses

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

type Graphite Uses

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

func NewGraphite Uses

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 Uses

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 Uses

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 Uses

type Kafka map[int32]*KafkaPartition

Kafka tracks the health of a consumer

func NewKafka Uses

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

type KafkaPartition Uses

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

KafkaPartition tracks the health of a partition consumer

func NewKafkaPartition Uses

func NewKafkaPartition(prefix string) *KafkaPartition

type LatencyHistogram12h32 Uses

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

tracks latency measurements in a given range as 32 bit counters

func NewLatencyHistogram12h32 Uses

func NewLatencyHistogram12h32(name string) *LatencyHistogram12h32

func NewLatencyHistogram12h32WithTags Uses

func NewLatencyHistogram12h32WithTags(name, tags string) *LatencyHistogram12h32

func (*LatencyHistogram12h32) Value Uses

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

func (*LatencyHistogram12h32) WriteGraphiteLine Uses

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

type LatencyHistogram15s32 Uses

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

tracks latency measurements in a given range as 32 bit counters

func NewLatencyHistogram15s32 Uses

func NewLatencyHistogram15s32(name string) *LatencyHistogram15s32

func NewLatencyHistogram15s32WithTags Uses

func NewLatencyHistogram15s32WithTags(name, tags string) *LatencyHistogram15s32

func (*LatencyHistogram15s32) Value Uses

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

func (*LatencyHistogram15s32) WriteGraphiteLine Uses

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

type MemoryReporter Uses

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 Uses

func NewMemoryReporter() *MemoryReporter

func (*MemoryReporter) WriteGraphiteLine Uses

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

type Meter32 Uses

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

func NewMeter32 Uses

func NewMeter32(name string, approx bool) *Meter32

func NewMeter32WithTags Uses

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

func (*Meter32) Value Uses

func (m *Meter32) Value(val int)

func (*Meter32) ValueUint32 Uses

func (m *Meter32) ValueUint32(val uint32)

func (*Meter32) Values Uses

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

func (*Meter32) ValuesUint32 Uses

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

func (*Meter32) WriteGraphiteLine Uses

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

type ProcessReporter Uses

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

ProcessReporter sources stats from /proc

func NewProcessReporter Uses

func NewProcessReporter() (*ProcessReporter, error)

func (*ProcessReporter) WriteGraphiteLine Uses

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

type Range32 Uses

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 Uses

func NewRange32(name string) *Range32

func NewRange32WithTags Uses

func NewRange32WithTags(name, tags string) *Range32

func (*Range32) Value Uses

func (r *Range32) Value(val int)

func (*Range32) ValueUint32 Uses

func (r *Range32) ValueUint32(val uint32)

func (*Range32) WriteGraphiteLine Uses

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

type Registry Uses

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

Registry tracks metrics and reporters

func NewRegistry Uses

func NewRegistry() *Registry

func (*Registry) Clear Uses

func (r *Registry) Clear()

type TimeDiffReporter32 Uses

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 Uses

func NewTimeDiffReporter32(name string, target uint32) *TimeDiffReporter32

func NewTimeDiffReporter32WithTags Uses

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

func (*TimeDiffReporter32) Set Uses

func (g *TimeDiffReporter32) Set(target uint32)

func (*TimeDiffReporter32) WriteGraphiteLine Uses

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

Directories

PathSynopsis
config

Package stats imports 19 packages (graph) and is imported by 76 packages. Updated 2020-06-12. Refresh now. Tools for package owners.