Documentation ¶
Index ¶
- Constants
- func NewStatsdSink(addr string, prefix string, maxDatagramsize int) (sink *statsdSink, err error)
- func NewTestSink(prefix string, maxDatagramsize int) (sink *testSink, err error)
- func SetDefaultOptions(opts ...MOption)
- func SetDefaultSink(sink Sink)
- func Start()
- func Stop()
- type AutoFlusher
- type Client
- func (c *Client) NewCounter(name string, opts ...MOption) *Counter
- func (c *Client) NewGauge(name string, opts ...MOption) *GaugeUint64
- func (c *Client) NewGaugeFloat64(name string, opts ...MOption) *GaugeFloat64
- func (c *Client) NewGaugeInt64(name string, opts ...MOption) *GaugeInt64
- func (c *Client) NewGaugeUint64(name string, opts ...MOption) *GaugeUint64
- func (c *Client) NewHistogram(name string, opts ...MOption) *Histogram
- func (c *Client) NewSet(name string, opts ...MOption) *Set
- func (c *Client) NewTimer(name string, opts ...MOption) *Timer
- func (c *Client) SetOptions(opts ...MOption)
- func (c *Client) SetSink(sink Sink)
- func (c *Client) Start()
- func (c *Client) Stop()
- type Counter
- type Flusher
- type FlusherSink
- type GaugeFloat64
- type GaugeInt64
- func (g *GaugeInt64) Clear()
- func (g *GaugeInt64) Count() int64
- func (g *GaugeInt64) Dec(i int64)
- func (g *GaugeInt64) Flush(f FlusherSink)
- func (g *GaugeInt64) Inc(i int64)
- func (g *GaugeInt64) Mtype() int
- func (g *GaugeInt64) Name() string
- func (g *GaugeInt64) Update(val int64)
- func (g *GaugeInt64) Value() int64
- type GaugeUint64
- type Histogram
- type MConfig
- type MOption
- type Meter
- type Numeric64
- type Option
- type Set
- type Sink
- type Timer
Examples ¶
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
Variables ¶
This section is empty.
Functions ¶
func NewStatsdSink ¶
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 ¶
func SetDefaultOptions ¶
func SetDefaultOptions(opts ...MOption)
Set options on the default metric client
Types ¶
type AutoFlusher ¶
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 ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
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.
Example ¶
package main import ( "github.com/One-com/gonelog/metric" "log" "strconv" "time" ) func main() { 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() }
Output:
func (*Client) NewGauge ¶
func (c *Client) NewGauge(name string, opts ...MOption) *GaugeUint64
NewGauge is alias for NewGaugeUint64
func (*Client) NewGaugeFloat64 ¶
func (c *Client) NewGaugeFloat64(name string, opts ...MOption) *GaugeFloat64
================================================================== An Float64 Gauge.
func (*Client) NewGaugeInt64 ¶
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 ¶
func (c *Client) NewGaugeUint64(name string, opts ...MOption) *GaugeUint64
NewGaugeUint64 returns a standard gauge.
func (*Client) NewHistogram ¶
func (*Client) SetOptions ¶
Set options on a client - like the flush interval for metrics which haven't them selves a fixed flush interval
type Counter ¶
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 ¶
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) Flush ¶
func (c *Counter) Flush(f FlusherSink)
type FlusherSink ¶
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 ¶
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 ¶
func (g *GaugeFloat64) Flush(f FlusherSink)
func (*GaugeFloat64) Mtype ¶
func (g *GaugeFloat64) Mtype() int
func (*GaugeFloat64) Name ¶
func (g *GaugeFloat64) Name() string
func (*GaugeFloat64) Update ¶
func (g *GaugeFloat64) Update(v float64)
Update updates the gauge's value.
func (*GaugeFloat64) Value ¶
func (g *GaugeFloat64) Value() float64
Value returns the gauge's current value.
type GaugeInt64 ¶
type GaugeInt64 struct {
// contains filtered or unexported fields
}
A gauge using an int64 - meaning it can be decremented to negaive values
func (*GaugeInt64) Dec ¶
func (g *GaugeInt64) Dec(i int64)
Dec decrements the counter by the given amount.
func (*GaugeInt64) Flush ¶
func (g *GaugeInt64) Flush(f FlusherSink)
func (*GaugeInt64) Inc ¶
func (g *GaugeInt64) Inc(i int64)
Inc increments the counter by the given amount.
func (*GaugeInt64) Mtype ¶
func (g *GaugeInt64) Mtype() int
func (*GaugeInt64) Name ¶
func (g *GaugeInt64) Name() string
func (*GaugeInt64) Update ¶
func (g *GaugeInt64) Update(val int64)
func (*GaugeInt64) Value ¶
func (g *GaugeInt64) Value() int64
type GaugeUint64 ¶
type GaugeUint64 struct {
// contains filtered or unexported fields
}
The default gauge type using a uint64
func NewGauge ¶
func NewGauge(name string, opts ...MOption) *GaugeUint64
================================================================== NewGauge is alias for NewGaugeUint64
func (*GaugeUint64) Flush ¶
func (g *GaugeUint64) Flush(f FlusherSink)
Flush to implement Meter interface
type Histogram ¶
type Histogram eventStream
A histogram is a series of int64 events all sent to the server
func NewHistogram ¶
type Meter ¶
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 ¶
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.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
func (*Set) Flush ¶
func (s *Set) Flush(f FlusherSink)
func (*Set) SetFlusher ¶
type Sink ¶
type Sink interface {
FlusherSink() FlusherSink
}
A factory for FlusherSinks. Metric clients are given a Sink to output to.