measures

package module
v0.0.0-...-464a821 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2019 License: MIT Imports: 4 Imported by: 0

README

Measure storage

This lib implements a simple in-memory measure storage which is optionally synced every N seconds with a persistent storage.

It's thread-safe and as simple as possible.

How to use

To initialize:

measures.Measures = measures.CreateMeasureStore(measures.NewRedisIncrementer("localhost", 6379),
	time.Second*10)

By default, an in-memory measure storage is used.

To write:

	measures.Measures.Inc("some_measure_1234234", 1.0)		

To read:

    	val, err := measures.Measures.Get("some_measure_1234234")
    	if err != nil {
    	    log.Fatal("error has occured", err)
    	}

It supports lazy loading, meaning that after restart, the measure will only be retrieved after it was first accessed.

Documentation

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type FloatMeasure

type FloatMeasure struct {
	Key string
	// contains filtered or unexported fields
}

func NewFloatMesure

func NewFloatMesure(key string, inc Incrementer, syncperiod time.Duration) (fm *FloatMeasure, err error)

func (*FloatMeasure) Get

func (m *FloatMeasure) Get() (ret float64)

func (*FloatMeasure) Inc

func (m *FloatMeasure) Inc(v float64)

type Incrementer

type Incrementer interface {
	IncAndGet(key string, by float64) (res float64, err error)
	Get(key string) (res float64, err error)
}

type Measure

type Measure interface {
	Inc(v float64)
	Get() (ret float64)
}

type MeasureStore

type MeasureStore struct {
	// contains filtered or unexported fields
}

func CreateMeasureStore

func CreateMeasureStore(inc Incrementer, synctime time.Duration) *MeasureStore

func (*MeasureStore) Get

func (ms *MeasureStore) Get(key string) (v float64, err error)

func (*MeasureStore) Inc

func (ms *MeasureStore) Inc(key string, v float64) (err error)

type MemIncrementer

type MemIncrementer struct {
	// contains filtered or unexported fields
}

func NewMemIncrementer

func NewMemIncrementer(startwith map[string]float64) (fi *MemIncrementer)

func (*MemIncrementer) Get

func (fi *MemIncrementer) Get(key string) (res float64, err error)

func (*MemIncrementer) IncAndGet

func (fi *MemIncrementer) IncAndGet(key string, by float64) (res float64, err error)

type RedisIncrementer

type RedisIncrementer struct {
	// contains filtered or unexported fields
}

func NewRedisIncrementer

func NewRedisIncrementer(host string, port int) (fi *RedisIncrementer)

func (*RedisIncrementer) Get

func (fi *RedisIncrementer) Get(key string) (res float64, err error)

func (*RedisIncrementer) IncAndGet

func (fi *RedisIncrementer) IncAndGet(key string, by float64) (res float64, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL