Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lyft/gostats
Go client for Stats
https://github.com/lyft/gostats
lyft
Last synced: 27 days ago
JSON representation
Go client for Stats
- Host: GitHub
- URL: https://github.com/lyft/gostats
- Owner: lyft
- License: other
- Created: 2016-12-27T22:01:18.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-05-16T18:52:29.000Z (7 months ago)
- Last Synced: 2024-05-22T14:33:47.340Z (7 months ago)
- Topics: lyft
- Language: Go
- Homepage:
- Size: 380 KB
- Stars: 55
- Watchers: 562
- Forks: 23
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-go-quant - gostats - Go client for Stats (Golang / Statistics)
README
# Gostats [![GoDoc](https://godoc.org/github.com/lyft/gostats?status.svg)](https://godoc.org/github.com/lyft/gostats) [![Build Status](https://github.com/lyft/gostats/actions/workflows/actions.yml/badge.svg?branch=master)](https://github.com/lyft/gostats/actions/workflows/actions.yml)
`gostats` is a Go metrics library with support for Counters, Gauges, and Timers.
## Installation
```sh
go get github.com/lyft/gostats
```## Building & Testing
```sh
go test ./...
```## Usage
In order to start using `gostats`, import it into your project with:
```go
import "github.com/lyft/gostats"
```## Mocking
A thread-safe mock sink is provided by the [gostats/mock](https://github.com/lyft/gostats/blob/mock-sink/mock/sink.go) package. The mock sink also provides methods that are useful for testing (as demonstrated below).
```go
package mock_testimport (
"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`:
```go
package configimport (
"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),
}
}
```