Documentation ¶
Overview ¶
Package stats provides a tool to collect and track statistics Example usage:
c := NewStatCollector("myapp") c.Child("performance").Child("net-latency").Value(200) c.Ch("performance").Ch("iops").V(100) c.Ch("hits") //defaults to int(0) c.Ch("hits").Incr() // add 1 hit fmt.Println(c.JSON())
Outputs
{"init": "2015-10-05T13:01:42.722509063-04:00", "changed": "0001-01-01T00:00:00Z", "value": 0, "children": { "hits": { "init": "2015-10-05T13:01:42.722511672-04:00", "changed": "0001-01-01T00:00:00Z", "value": 1 }, "performance": { "init": "2015-10-05T13:01:42.72250972-04:00", "changed": "0001-01-01T00:00:00Z", "value": 0, "children": { "iops": { "init": "2015-10-05T13:01:42.722511208-04:00", "changed": "2015-10-05T13:01:42.722511477-04:00", "value": 100 }, "net-latency": { "init": "2015-10-05T13:01:42.7225103-04:00", "changed": "2015-10-05T13:01:42.722510848-04:00", "value": 200 } } } }}
Index ¶
- type Collector
- func (c *Collector) Avg(nextval float32) *Collector
- func (c *Collector) AvgLen(init float32, length int) *Collector
- func (c *Collector) Ch(name string) *Collector
- func (c *Collector) Child(name string) *Collector
- func (c *Collector) Decr() *Collector
- func (c *Collector) DisableTimes()
- func (c *Collector) EnableTimes()
- func (c *Collector) GetV() interface{}
- func (c *Collector) Has(name string) bool
- func (c *Collector) Incr() *Collector
- func (c *Collector) JSON() (string, error)
- func (c *Collector) Name() string
- func (c *Collector) V(v interface{}) *Collector
- func (c *Collector) Value(v interface{}) *Collector
- func (c *Collector) Vf(f float64) *Collector
- func (c *Collector) Vi(i int64) *Collector
- func (c *Collector) Vs(s string) *Collector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collector ¶
type Collector struct { StatName string `json:"-"` InitDate *time.Time `json:"init,omitempty"` ChangeDate *time.Time `json:"changed,omitempty"` StatValue interface{} `json:"value"` Children map[string]*Collector `json:"children,omitempty"` DisableTime bool `json:"-"` // contains filtered or unexported fields }
Collector stores a stat name, value, and its children. DisableTime is inherited by children automatically
func NewStatCollector ¶
NewStatCollector Creates an empty new collector with default stat value of int64(0) Enables timestamp collection by default
func (*Collector) Avg ¶
Avg takes the next value in a sequence to average and store for this stat If AvgLen hasn't been called yet to init this stat, default length of 10 is used.
func (*Collector) AvgLen ¶
AvgLen sets the value as an array where index 0 is the computed average. It sets the length of items to store to compute that average, if it has not been set. If it has been set already, then it will ignore this call.
func (*Collector) Decr ¶
Decr subtracts from the current stat value by 1 (or 1.0 for float) Supported types: int, int32, int64, float32, float64, others are ignored
func (*Collector) DisableTimes ¶
func (c *Collector) DisableTimes()
DisableTimes sets init to 0, changed to 0, and disables the timestamp collection for this item
func (*Collector) EnableTimes ¶
func (c *Collector) EnableTimes()
EnableTimes sets init to time.Now(), leaves changed alone, and enables the timestamp collection for this item
func (*Collector) GetV ¶
func (c *Collector) GetV() interface{}
GetV returns the collectors stat value
func (*Collector) Has ¶
Has checks if a child stat name exists on the collector, returns true if exists
func (*Collector) Incr ¶
Incr adds to the current stat value by 1 (or 1.0 for float) Supported types: int, int32, int64, float32, float64, others are ignored
func (*Collector) JSON ¶
JSON Returns the collector and its children in serialized JSON format
{ "init": "1999-10-05T12:25:08.793401767-04:00", "changed": "0001-01-01T00:00:00Z", "value": 0, "children": { "c1": { "init": "1999-10-05T12:25:08.793402159-04:00", "changed": "2001-10-05T12:25:08.79340264-04:00", "value": 1 } } }