metrics

package
v0.0.0-...-1676a5e Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 4 Imported by: 0

README

metrics

Metrics

Usage

import "metrics"

var met metrics.Metrics{
			Timers: map[string]*metrics.Timer{
				"timerName": &metrics.Timer{
					Name : "timerName",
					BufferSize: 1000,
				},
			},
			Counters: map[string]*metrics.Counter{
				"counterName" : &metrics.Counter{
					Name : "counterName",
				},
			},
			MultiCounters: map[string]*metrics.MultiCounter{
				"multiCounterName" : &metrics.MultiCounter{
					Name : "multiCounterName",
					Counters : map[string]*metrics.Counter{},
				},
			}

var resultsMap map[string]interface{}
func timerExampele() {
	met.Timers["timerName"].Start()

	//stuff to time

	met.Timers["timerName"].Stop()
	met.Timers["timerName"].Update(&resultsMap)
}

func counterExample() {

	//stuff to count

	met.Counters["counterName"].Increment()
	met.Counters["counterName"].Update(&resultsMap)
}
func multiCounterExample() {

	//stuff to count

	met.MultiCounters["multiCounterName"].Increment("counterName")
	met.MultiCounters["multiCounterName"].Update(&resultsMap)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter struct {
	Name string

	sync.RWMutex
	// contains filtered or unexported fields
}

Counter is a simple counter

func (*Counter) GetValue

func (self *Counter) GetValue() uint64

GetValue is a method to directly get the current value of the counter

func (*Counter) Increment

func (self *Counter) Increment()

Incrememt increments the counter by 1. Call this function where the action want to count is.

func (*Counter) Reset

func (self *Counter) Reset()

Reset resets the counter to 0

func (*Counter) Update

func (self *Counter) Update(f func(k string, v interface{}))

Update is called to save the value the counterinto the results map. You can pass any map[string]Interface{} to store results including the provide Results map on the main Metrics struct

type Metrics

type Metrics struct {
	Timers        map[string]*Timer
	Counters      map[string]*Counter
	MultiCounters map[string]*MultiCounter

	sync.RWMutex
	// contains filtered or unexported fields
}

Metrics is the main object to instantiate when using the metrics package. One instance of a Metrics object will contain all your timers and counters and results

func NewMetrics

func NewMetrics() Metrics

func (*Metrics) MarshalResults

func (self *Metrics) MarshalResults() ([]byte, error)

func (*Metrics) SetResults

func (self *Metrics) SetResults(k string, v interface{})

type MultiCounter

type MultiCounter struct {
	Name     string
	Counters map[string]*Counter

	sync.RWMutex
	// contains filtered or unexported fields
}

MultiCounter is a collection of counters. Useful for making comparisons between groups of similar statistics

func (*MultiCounter) Get

func (self *MultiCounter) Get(counter string) (c *Counter)

func (*MultiCounter) Increment

func (self *MultiCounter) Increment(counter string)

Increment increments specific counter by 1

func (*MultiCounter) Reset

func (self *MultiCounter) Reset(counter string)

Reset resets specific counter

func (*MultiCounter) Update

func (self *MultiCounter) Update(f func(k string, v interface{}))

Update is called to save the values of all counters into the results map. You can pass any map[string]Interface{} to store results including the provide Results map on the main Metrics struct

type Results

type Results struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

type Timer

type Timer struct {
	Name       string
	BufferSize uint64

	sync.RWMutex
	// contains filtered or unexported fields
}

Timer is a simple timer used to measure time taken to perform given tasks in microseconds

func (*Timer) Start

func (self *Timer) Start() error

Start starts the timer. Place what needs to be timed in between Start() and Stop()

func (*Timer) Stop

func (self *Timer) Stop()

Stop stops the timer

func (*Timer) Update

func (self *Timer) Update(f func(k string, v interface{}))

Update is called to save the values of the timer into the results map. You can pass any map[string]Interface{} to store results including the provide Results map on the main Metrics struct

Jump to

Keyboard shortcuts

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