fletcherist / stata

counters for events

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stata

Pure Go, Simple, Time-Series Counters for analytics

  • aims to support all popular databases

Install

  1. Install library
go get github.com/fletcherist/stata
  1. Select storage for your database
# foundationdb db
go get github.com/fletcherist/stata/fdb
# redis
go get github.com/fletcherist/stata/redis
  1. 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)
}

install json datasource

Grafana JSON Datasource

grafana-cli plugins install simpod-json-datasource

About

counters for events

License:MIT License


Languages

Language:Go 100.0%