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 ¶
- func Clear()
- func NewDevnull()
- func WriteFloat64(buf, prefix, name, suffix, tags []byte, val float64, now time.Time) []byte
- func WriteInt32(buf, prefix, name, suffix, tags []byte, val int32, now time.Time) []byte
- func WriteUint32(buf, prefix, name, suffix, tags []byte, val uint32, now time.Time) []byte
- func WriteUint64(buf, prefix, name, suffix, tags []byte, val uint64, now time.Time) []byte
- type Bool
- type Counter32
- type Counter64
- type CounterRate32
- type Gauge32
- func (g *Gauge32) Add(val int)
- func (g *Gauge32) AddUint32(val uint32)
- func (g *Gauge32) Dec()
- func (g *Gauge32) DecUint32(val uint32)
- func (g *Gauge32) Inc()
- func (g *Gauge32) Set(val int)
- func (g *Gauge32) SetUint32(val uint32)
- func (g *Gauge32) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte
- type Gauge64
- func (g *Gauge64) Add(val int)
- func (g *Gauge64) AddUint64(val uint64)
- func (g *Gauge64) Dec()
- func (g *Gauge64) DecUint64(val uint64)
- func (g *Gauge64) Inc()
- func (g *Gauge64) Peek() uint64
- func (g *Gauge64) Set(val int)
- func (g *Gauge64) SetUint64(val uint64)
- func (g *Gauge64) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte
- type Graphite
- type GraphiteMetric
- type Kafka
- type KafkaPartition
- type LatencyHistogram12h32
- type LatencyHistogram15s32
- type MemoryReporter
- type Meter32
- type ProcessReporter
- type Range32
- type Registry
- type TimeDiffReporter32
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 NewBoolWithTags ¶ added in v1.0.0
func NewBoolWithTags(name, tags string) *Bool
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) 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) 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) 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) 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) 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
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
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) 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) 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) ValueUint32 ¶
func (m *Meter32) ValueUint32(val uint32)
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) 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
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) WriteGraphiteLine ¶ added in v1.0.0
func (g *TimeDiffReporter32) WriteGraphiteLine(buf, prefix []byte, now time.Time) []byte