statter

package module
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: MIT Imports: 9 Imported by: 12

README

Logo

Go Report Card Build Status Coverage Status Go Reference GitHub release GitHub license

Go stats clients

Overview

Install with:

go get github.com/hamba/statter/v2
Supported stats clients
  • L2met Writes l2met to a Logger interface
  • Statsd Writes statsd to UDP
  • Prometheus Exposes stats via HTTP
  • VictoriaMetrics Exposes stats via HTTP

Note: This project has renamed the default branch from master to main. You will need to update your local environment.

Usage

reporter := statsd.New(statsdAddr, "")
stats := statter.New(reporter, 10*time.Second).With("my-prefix")

stats.Counter("my-counter", tags.Str("tag", "value")).Inc(1)

Documentation

Overview

Package statter is a statistics collector with multiple reporters..

Index

Examples

Constants

This section is empty.

Variables

View Source
var DiscardReporter = discardReporter{}

DiscardReporter is a reporter that discards all stats.

Functions

This section is empty.

Types

type Counter

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

Counter implements a counter.

func (*Counter) Inc

func (c *Counter) Inc(v int64)

Inc increments the counter.

Example
stat := statter.New(statter.DiscardReporter, time.Second)

stat.Counter("my_counter", tags.Str("tag", "value")).Inc(1)
Output:

type Gauge

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

Gauge implements a gauge.

func (*Gauge) Set

func (g *Gauge) Set(v float64)

Set sets the gauge value.

Example
stat := statter.New(statter.DiscardReporter, time.Second)

stat.Gauge("my_gauge", tags.Int("int", 1)).Set(1.23)
Output:

type Histogram

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

Histogram implements a histogram.

func (*Histogram) Observe

func (h *Histogram) Observe(v float64)

Observe observes a histogram value.

Example
stat := statter.New(statter.DiscardReporter, time.Second)

stat.Histogram("my_histo", tags.Str("label", "blah")).Observe(2.34)
Output:

type HistogramReporter

type HistogramReporter interface {
	Histogram(name string, tags [][2]string) func(v float64)
}

HistogramReporter represents a stats reporter that handles histograms.

type Option

type Option func(*config)

Option represents a statter option function.

func WithPercentileSamples

func WithPercentileSamples(n int) Option

WithPercentileSamples sets the number of samples taken to calculate percentiles.

func WithPercentiles

func WithPercentiles(p []float64) Option

WithPercentiles sets the percentiles to calculate and report for aggregated histograms and timings.

func WithPrefix added in v2.3.3

func WithPrefix(prefix string) Option

WithPrefix sets the initial prefix on a statter.

func WithSeparator

func WithSeparator(sep string) Option

WithSeparator sets the key separator on a statter.

func WithTags added in v2.3.3

func WithTags(tags ...Tag) Option

WithTags sets the initial tags on a statter.

type Reporter

type Reporter interface {
	Counter(name string, v int64, tags [][2]string)
	Gauge(name string, v float64, tags [][2]string)
}

Reporter represents a stats reporter.

type Statter

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

Statter collects and reports stats.

func New

func New(r Reporter, interval time.Duration, opts ...Option) *Statter

New returns a statter.

func (*Statter) Close

func (s *Statter) Close() error

Close closes the statter and reporter.

func (*Statter) Counter

func (s *Statter) Counter(name string, tags ...Tag) *Counter

Counter returns a counter for the given name and tags.

func (*Statter) FullName added in v2.2.0

func (s *Statter) FullName(name string) string

FullName returns the full name with prefix for the given name.

func (*Statter) Gauge

func (s *Statter) Gauge(name string, tags ...Tag) *Gauge

Gauge returns a gauge for the given name and tags.

func (*Statter) Histogram

func (s *Statter) Histogram(name string, tags ...Tag) *Histogram

Histogram returns a histogram for the given name and tags.

func (*Statter) Reporter added in v2.1.1

func (s *Statter) Reporter() Reporter

Reporter returns the stats reporter.

The reporter should not be used directly.

func (*Statter) Timing

func (s *Statter) Timing(name string, tags ...Tag) *Timing

Timing returns a timing for the given name and tags.

func (*Statter) With

func (s *Statter) With(prefix string, tags ...Tag) *Statter

With returns a statter with the given prefix and tags.

type Tag

type Tag [2]string

Tag is a stat tag.

type Timing

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

Timing implements a timing.

func (*Timing) Observe

func (t *Timing) Observe(d time.Duration)

Observe observes a timing duration.

If the reporter does not handle timings, the duration will be aggregated in milliseconds.

type TimingReporter

type TimingReporter interface {
	Timing(name string, tags [][2]string) func(v time.Duration)
}

TimingReporter represents a stats reporter that handles timings.

Directories

Path Synopsis
internal
bytes
Package bytes implements performant bytes implementations.
Package bytes implements performant bytes implementations.
stats
Package stats implements performant statistics implementations.
Package stats implements performant statistics implementations.
reporter
l2met
Package l2met implements an l2met stats client.
Package l2met implements an l2met stats client.
prometheus
Package prometheus implements an prometheus stats client.
Package prometheus implements an prometheus stats client.
statsd
Package statsd implements an statsd client.
Package statsd implements an statsd client.
victoriametrics
Package victoriametrics implements an victoria metrics stats reporter.
Package victoriametrics implements an victoria metrics stats reporter.
Package runtime implements runtime stats collection convenience functions.
Package runtime implements runtime stats collection convenience functions.
Package tags implements statter tags convenience functions.
Package tags implements statter tags convenience functions.

Jump to

Keyboard shortcuts

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