Documentation ¶
Index ¶
Constants ¶
const NsInSec = float64(time.Second)
nanoseconds in a second represented in float64
Variables ¶
var Percentiles = []float64{50, 75, 95, 99, 99.9, 99.99, 99.999}
Percentiles are default percentiles to compute when serializing statstimer type to stdout/json
Functions ¶
This section is empty.
Types ¶
type BasicCounter ¶
type BasicCounter uint64
BasicCounter is a minimal counter(uint64) - all operations are atomic Usage:
b := metrics.NewBasicCounter() b.Add(1) b.Get()
func NewBasicCounter ¶
func NewBasicCounter() *BasicCounter
NewBasicCounter initializes and returns a BasicCounter
func (*BasicCounter) MarshalJSON ¶
func (c *BasicCounter) MarshalJSON() ([]byte, error)
MarshalJSON returns a byte slice of JSON representation of basiccounter
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter represents an always incrementing metric type Counter differs from BasicCounter by having additional fields for computing rate. Operations on counter hold a mutex. use BasicCounter if you need lock-free counters
func (*Counter) ComputeRate ¶
ComputeRate calculates the rate of change of counter per second. (acquires a lock)
func (*Counter) MarshalJSON ¶
MarshalJSON returns a byte slice of JSON representation of counter
type Gauge ¶
type Gauge struct {
// contains filtered or unexported fields
}
Gauge represents a metric of type Gauge. An example would be number of users logged in at the moment.
func (*Gauge) MarshalJSON ¶
MarshalJSON returns a byte slice of JSON representation of Gauge
type MetricContext ¶
type MetricContext struct { Counters map[string]*Counter Gauges map[string]*Gauge BasicCounters map[string]*BasicCounter StatsTimers map[string]*StatsTimer OutputFilter OutputFilterFunc // contains filtered or unexported fields }
MetricContext represents a reference to all metrics registered by name within a namespace
func NewMetricContext ¶
func NewMetricContext(namespace string) *MetricContext
NewMetricContext initializes a MetricContext with the input namespace and returns it
func (*MetricContext) EncodeJSON ¶
func (m *MetricContext) EncodeJSON(w io.Writer) error
EncodeJSON is a streaming encoder that writes all metrics passing filter to writer w as JSON
func (*MetricContext) HttpJsonHandler ¶
func (m *MetricContext) HttpJsonHandler(w http.ResponseWriter, r *http.Request)
HttpJsonHandler setups a handler for exposing metrics via JSON over HTTP
func (*MetricContext) Register ¶
func (m *MetricContext) Register(v interface{}, name string)
Register registers a metric with metriccontext
func (*MetricContext) Unregister ¶
func (m *MetricContext) Unregister(v interface{}, name string)
Unregister unregisters a metric with metriccontext
type MetricJSON ¶
MetricJSON is a type for serializing any metric type
type OutputFilterFunc ¶
OutputFilterFunc represents a function that is used to filter metrics from being reported out from JSON handler
type StatsTimer ¶
type StatsTimer struct {
// contains filtered or unexported fields
}
StatsTimer represents a metric of type statstimer
func NewStatsTimer ¶
func NewStatsTimer(timeUnit time.Duration, nsamples int) *StatsTimer
NewStatsTimer initializes and returns a StatsTimer. StatTimer can be used to compute statistics for a timed operation. Arguments:
timeUnit time.Duration - time unit to report statistics on nsamples int - number of samples to keep in-memory for stats computation
Example:
m := metrics.NewMetricContext("webapp") s := m.NewStatsTimer("latency", time.Millisecond, 100) func (wa *WebApp) HandleQuery(w http.ResponseWriter, r *http.Request) { stopWatch := s.Start() ... do work... s.Stop(stopWatch) } pctile95, err := s.Percentile(95) if err == nil { fmt.Printf("95th percentile for latency: ", pctile95) }
func (*StatsTimer) MarshalJSON ¶
func (s *StatsTimer) MarshalJSON() ([]byte, error)
MarshalJSON returns a byte slice containing representation of StatsTimer
func (*StatsTimer) Percentile ¶
func (s *StatsTimer) Percentile(percentile float64) (float64, error)
Percentile returns the value at input percentile Implementation is based on Nearest rank http://en.wikipedia.org/wiki/Percentile
func (*StatsTimer) Start ¶
func (s *StatsTimer) Start() *Timer
Start - Start a stopWatch for the StatsTimer and returns it
func (*StatsTimer) Stop ¶
func (s *StatsTimer) Stop(t *Timer) float64
Stop - Stops the stopWatch for the StatsTimer.