Skip to content
lyftPublic

About

Go client for Stats

Topics

Resources

Code of conduct

Contributing

Stars

58 stars

Watchers

557 watching

Forks

Latest commit

 

History

112 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gostats GoDoc Build Status

gostats is a Go metrics library with support for Counters, Gauges, and Timers.

Installation

go get github.com/lyft/gostats

Building & Testing

go test ./...

Usage

In order to start using gostats, import it into your project with:

import "github.com/lyft/gostats"

Bounding memory from high-cardinality tags

By default, gostats never forgets a counter or timer name once it sees one, even after the value stops changing. Don't tag one with a high-cardinality value: that grows memory without limit. GOSTATS_PRUNE_IDLE_SECONDS limits the growth. See docs/idle-pruning.md for how it works and how to pick a value.

Mocking

A thread-safe mock sink is provided by the gostats/mock package. The mock sink also provides methods that are useful for testing (as demonstrated below).

package mock_test

import (
	"testing"

	"github.com/lyft/gostats"
	"github.com/lyft/gostats/mock"
)

type Config struct {
	Stats stats.Store
}

func TestMockExample(t *testing.T) {
	sink := mock.NewSink()
	conf := Config{
		Stats: stats.NewStore(sink, false),
	}
	conf.Stats.NewCounter("name").Inc()
	conf.Stats.Flush()
	sink.AssertCounterEquals(t, "name", 1)
}

If you do not need to assert on the contents of the sink the below example can be used to quickly create a thread-safe stats.Scope:

package config

import (
	"github.com/lyft/gostats"
	"github.com/lyft/gostats/mock"
)

type Config struct {
	Stats stats.Store
}

func NewConfig() *Config {
	return &Config{
		Stats: stats.NewDefaultStore(),
	}
}

func NewMockConfig() *Config {
	sink := mock.NewSink()
	return &Config{
		Stats: stats.NewStore(sink, false),
	}
}

About

Go client for Stats

Topics

Resources

Code of conduct

Contributing

Stars

58 stars

Watchers

557 watching

Forks

Releases

Packages

Used by

Contributors

Languages