Skip to content

Repository files navigation

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)

Scopes

A Scope is a sub-statter identified by an id, which tracks the metrics created through it.

Requesting a scope with an existing id but different tags removes the previous scope and every metric created through it. This keeps a metric unique for a set of tags, such as a gauge carrying a revision that changes over time:

stats.Scope("build-info", tags.Str("revision", rev)).Gauge("info").Set(1)

The tracked metrics can also be removed together as a batch:

scope := stats.Scope("tenant:"+id, tags.Str("tenant", id))
scope.Counter("requests").Inc(1)
scope.Timing("latency").Observe(d)

scope.Delete() // Both metrics are removed.

Use HasScope to determine if a scope currently exists.

Note: Metrics are only removed from the backend if the reporter supports removal, which the Prometheus and VictoriaMetrics reporters do. Otherwise deletion only stops local aggregation.

About

Go stats clients

Topics

Resources

Code of conduct

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages