Pure Go, Simple, Time-Series Counters for analytics
- aims to support all popular databases
- Install library
go get github.com/fletcherist/stata
- Select storage for your database
- redis
- foundationdb
- memory
- you can easily implement your own storage backend
# foundationdb db
go get github.com/fletcherist/stata/fdb
# redis
go get github.com/fletcherist/stata/redis
- Working example
package main
import (
"fmt"
"github.com/fletcherist/stata"
)
func main() {
// create storage where counters would be stored
storage := stata.NewMemoryStorage()
// create client with storage
stataClient := stata.New(&stata.Config{Storage: storage})
counter := stataClient.Event("simple-counter", stata.EventConfig{
Bins: []stata.Bin{ // time-series intervals for storing counters
stata.Bins.Minute, // counts number of events for every minute
},
})
// to test counter lets increment it's value 3 times
counter.Inc()
counter.Inc()
counter.Inc()
// now lets count how many events we've got for that minute (3 events)
value, _ := stataClient.Get(stata.Key{
Name: counter.Name,
Bin: stata.Bins.Minute,
})
// prints "3"
fmt.Println(value)
}
grafana-cli plugins install simpod-json-datasource