gonelog: github.com/One-com/gonelog/metric Index | Examples | Files

package metric

import "github.com/One-com/gonelog/metric"

Index

Examples

Package Files

client.go counter.go event.go flusher.go gauge.go histotimer.go meter.go moptions.go numeric64.go set.go statsd.go testsink.go

Constants

const (
    MeterGauge     = iota // A client side maintained value
    MeterCounter          // A server side maintained value
    MeterHistogram        // A general distribution of measurements events.
    MeterTimer            // ... when those measurements are milliseconds
    MeterSet              // free form string events
)

Conceptual meter types Gauge: A client side maintained counter Counter: A server side maintained counter Historam: A series of events analyzed on the server Timer: A series of time.Duration events analyzed on the server Set: Discrete strings added to a set maintained on the server

const (
    Uint64 = iota
    Int64
    Float64
)

Data types for Numeric64

func NewStatsdSink Uses

func NewStatsdSink(addr string, prefix string, maxDatagramsize int) (sink *statsdSink, err error)

A Sink sending data to a UDP statsd server Provide a UDP address, a prefix and a maximum UDP datagram size. 1432 should be a safe size for most nets.

func NewTestSink Uses

func NewTestSink(prefix string, maxDatagramsize int) (sink *testSink, err error)

func SetDefaultOptions Uses

func SetDefaultOptions(opts ...MOption)

Set options on the default metric client

func SetDefaultSink Uses

func SetDefaultSink(sink Sink)

Set the Sink factory of the default client

func Start Uses

func Start()

Start the default client if stopped.

func Stop Uses

func Stop()

Stops the global default metrics client

type AutoFlusher Uses

type AutoFlusher interface {
    SetFlusher(*Flusher)
}

An AutoFlusher can initiate a Flush throught the flusher at any time and needs to know the Flusher to call FlushMeter() on it

type Client Uses

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

func NewClient Uses

func NewClient(sink Sink, opts ...MOption) (client *Client)

NewClient returns you a client handle directly if you do not want to use the global default client. Create a new metric client with a factory object for the sink. If sink == nil, the client will not emit metrics until a Sink is set.

Code:


var _flushPeriod = 4 * time.Second

sink, err := metric.NewTestSink("prefix", 1432)
if err != nil {
    log.Fatal(err)
}
flushPeriod := metric.FlushInterval(_flushPeriod)

c := metric.NewClient(sink, flushPeriod)

gauge := c.NewGauge("gauge", flushPeriod)
timer := c.NewTimer("timer")
histo := c.NewHistogram("histo", flushPeriod)
counter := c.NewCounter("counter", flushPeriod)
set := c.NewSet("set", flushPeriod)

g := 100
for g != 0 {
    counter.Inc(1)
    gauge.Update(uint64(g))
    timer.Update(time.Duration(g) * time.Millisecond)
    histo.Update(int64(g))
    set.Update(strconv.FormatInt(int64(g), 10))

    time.Sleep(time.Second)
    g--
}
c.Stop()

func (*Client) NewCounter Uses

func (c *Client) NewCounter(name string, opts ...MOption) *Counter

func (*Client) NewGauge Uses

func (c *Client) NewGauge(name string, opts ...MOption) *GaugeUint64

NewGauge is alias for NewGaugeUint64

func (*Client) NewGaugeFloat64 Uses

func (c *Client) NewGaugeFloat64(name string, opts ...MOption) *GaugeFloat64

================================================================== An Float64 Gauge.

func (*Client) NewGaugeInt64 Uses

func (c *Client) NewGaugeInt64(name string, opts ...MOption) *GaugeInt64

An Int64 Gauge. Can be used as a go-metric client side gauge or counter

func (*Client) NewGaugeUint64 Uses

func (c *Client) NewGaugeUint64(name string, opts ...MOption) *GaugeUint64

NewGaugeUint64 returns a standard gauge.

func (*Client) NewHistogram Uses

func (c *Client) NewHistogram(name string, opts ...MOption) *Histogram

func (*Client) NewSet Uses

func (c *Client) NewSet(name string, opts ...MOption) *Set

func (*Client) NewTimer Uses

func (c *Client) NewTimer(name string, opts ...MOption) *Timer

func (*Client) SetOptions Uses

func (c *Client) SetOptions(opts ...MOption)

Set options on a client - like the flush interval for metrics which haven't them selves a fixed flush interval

func (*Client) SetSink Uses

func (c *Client) SetSink(sink Sink)

The the Sink factory of the client

func (*Client) Start Uses

func (c *Client) Start()

Start a stopped client

func (*Client) Stop Uses

func (c *Client) Stop()

Stop a Client from flushing data. If any AutoFlusher meters are still in use they will still flush when overflown.

type Counter Uses

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

Counter is different from a GaugeInt64 in that it is reset to zero every time its flushed - and thus being server-side maintained.

func NewCounter Uses

func NewCounter(name string, opts ...MOption) *Counter

A server side maintained counter. "Server side" meaning that it's reset to 0 every time it's sent to the server and the tally is kept on the server This poses the risk of the server-side absolute value to drift in case of increments lost in transit. However, it also allows several processes to update the same counter. If you want to have a client side counter, use GaugeInt64

func (*Counter) Dec Uses

func (c *Counter) Dec(i int64)

func (*Counter) Flush Uses

func (c *Counter) Flush(f FlusherSink)

func (*Counter) Inc Uses

func (c *Counter) Inc(val int64)

func (*Counter) Mtype Uses

func (c *Counter) Mtype() int

func (*Counter) Name Uses

func (c *Counter) Name() string

type Flusher Uses

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

func (*Flusher) Flush Uses

func (f *Flusher) Flush()

flush all meters

func (*Flusher) FlushMeter Uses

func (f *Flusher) FlushMeter(m Meter)

flush a single Meter

type FlusherSink Uses

type FlusherSink interface {
    Emit(name string, mtype int, value interface{})
    EmitNumeric64(name string, mtype int, value Numeric64)
    Flush()
}

FlusherSink is a Sink for metrics data which methods are guaranteed to be called synchronized. This it can keep state like buffers without locking

type GaugeFloat64 Uses

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

A go-metric compatible float64 gauge which stores its value as a uint64 to implement Flush() fast

func (*GaugeFloat64) Flush Uses

func (g *GaugeFloat64) Flush(f FlusherSink)

func (*GaugeFloat64) Mtype Uses

func (g *GaugeFloat64) Mtype() int

func (*GaugeFloat64) Name Uses

func (g *GaugeFloat64) Name() string

func (*GaugeFloat64) Update Uses

func (g *GaugeFloat64) Update(v float64)

Update updates the gauge's value.

func (*GaugeFloat64) Value Uses

func (g *GaugeFloat64) Value() float64

Value returns the gauge's current value.

type GaugeInt64 Uses

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

A gauge using an int64 - meaning it can be decremented to negaive values

func (*GaugeInt64) Clear Uses

func (g *GaugeInt64) Clear()

Clear sets the counter to zero.

func (*GaugeInt64) Count Uses

func (g *GaugeInt64) Count() int64

Count returns the current count.

func (*GaugeInt64) Dec Uses

func (g *GaugeInt64) Dec(i int64)

Dec decrements the counter by the given amount.

func (*GaugeInt64) Flush Uses

func (g *GaugeInt64) Flush(f FlusherSink)

func (*GaugeInt64) Inc Uses

func (g *GaugeInt64) Inc(i int64)

Inc increments the counter by the given amount.

func (*GaugeInt64) Mtype Uses

func (g *GaugeInt64) Mtype() int

func (*GaugeInt64) Name Uses

func (g *GaugeInt64) Name() string

func (*GaugeInt64) Update Uses

func (g *GaugeInt64) Update(val int64)

func (*GaugeInt64) Value Uses

func (g *GaugeInt64) Value() int64

type GaugeUint64 Uses

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

The default gauge type using a uint64

func NewGauge Uses

func NewGauge(name string, opts ...MOption) *GaugeUint64

================================================================== NewGauge is alias for NewGaugeUint64

func (*GaugeUint64) Dec Uses

func (g *GaugeUint64) Dec(i int64)

Decrement the gauge value

func (*GaugeUint64) Flush Uses

func (g *GaugeUint64) Flush(f FlusherSink)

Flush to implement Meter interface

func (*GaugeUint64) Inc Uses

func (g *GaugeUint64) Inc(i uint64)

Increment the gauge value

func (*GaugeUint64) Mtype Uses

func (g *GaugeUint64) Mtype() int

Mtype to implement Meter interface

func (*GaugeUint64) Name Uses

func (g *GaugeUint64) Name() string

Name to implement Meter interface

func (*GaugeUint64) Update Uses

func (g *GaugeUint64) Update(val uint64)

Update the gauge value

func (*GaugeUint64) Value Uses

func (g *GaugeUint64) Value() uint64

Get the gauge value

type Histogram Uses

type Histogram eventStream

A histogram is a series of int64 events all sent to the server

func NewHistogram Uses

func NewHistogram(name string, opts ...MOption) *Histogram

func (*Histogram) Update Uses

func (h *Histogram) Update(d int64)

Update the Histogram by registering a new event

type MConfig Uses

type MConfig map[string]interface{}

type MOption Uses

type MOption func(MConfig)

func FlushInterval Uses

func FlushInterval(d time.Duration) MOption

type Meter Uses

type Meter interface {
    Mtype() int
    Name() string
    Flush(FlusherSink) // Read the meter, by flushing all non-read values.
}

A Meter measures stuff and can be registered with a client to be periodically reported to the Sink

type Numeric64 Uses

type Numeric64 struct {
    Type int
    // contains filtered or unexported fields
}

Numeric64 is an internal datatype used to generalize an eventStream to hold any 64 bit numeric value. This is a performance optimation. An interface{} would require additional dynamic allocation of heap objects.

func (Numeric64) Float64 Uses

func (n Numeric64) Float64() float64

func (Numeric64) Int64 Uses

func (n Numeric64) Int64() int64

func (Numeric64) Uint64 Uses

func (n Numeric64) Uint64() uint64

type Option Uses

type Option func(*config)

type Set Uses

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

func NewSet Uses

func NewSet(name string, opts ...MOption) *Set

func (*Set) Flush Uses

func (s *Set) Flush(f FlusherSink)

func (*Set) Mtype Uses

func (s *Set) Mtype() int

func (*Set) Name Uses

func (s *Set) Name() string

func (*Set) SetFlusher Uses

func (s *Set) SetFlusher(f *Flusher)

func (*Set) Update Uses

func (s *Set) Update(val string)

type Sink Uses

type Sink interface {
    FlusherSink() FlusherSink
}

A factory for FlusherSinks. Metric clients are given a Sink to output to.

type Timer Uses

type Timer eventStream

Timer is like Histogram, but the event is a time.Duration. values are remembered as milliseconds

func NewTimer Uses

func NewTimer(name string, opts ...MOption) *Timer

func (*Timer) Update Uses

func (t *Timer) Update(d time.Duration)

Register a new duration event.

Package metric imports 8 packages (graph). Updated 2016-08-01. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).