metrics

package
v0.0.0-...-c2bae5a Latest Latest
Warning

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

Go to latest
Published: May 12, 2015 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

Metrics is the default metric system, which collects and broadcasts metrics to subscribers once every 60 seconds. Also includes default system stats.

Functions

This section is empty.

Types

type MetricSystem

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

MetricSystem facilitates the collection and distribution of metrics.

Example
ms := NewMetricSystem(time.Microsecond, true)
ms.Start()
myMetricStream := make(chan *ProcessedMetricSet, 2)
ms.SubscribeToProcessedMetrics(myMetricStream)

timeToken := ms.StartTimer("submit_metrics")
ms.Counter("range_splits", 1)
ms.Histogram("some_ipc_latency", 123)
ms.StopTimer(timeToken)

processedMetricSet := <-myMetricStream
ms.UnsubscribeFromProcessedMetrics(myMetricStream)

m := processedMetricSet.Metrics

example := []struct {
	Name  string
	Value float64
}{
	{
		"total range splits during the process lifetime",
		m["range_splits"],
	}, {
		"range splits in this period",
		m["range_splits_rate"],
	}, {
		"some_ipc 99.9th percentile",
		m["some_ipc_latency_99.9"],
	}, {
		"some_ipc max",
		m["some_ipc_latency_max"],
	}, {
		"some_ipc calls this period",
		m["some_ipc_latency_count"],
	}, {
		"some_ipc calls during the process lifetime",
		m["some_ipc_latency_agg_count"],
	}, {
		"some_ipc total latency this period",
		m["some_ipc_latency_sum"],
	}, {
		"some_ipc mean this period",
		m["some_ipc_latency_avg"],
	}, {
		"some_ipc aggregate man",
		m["some_ipc_latency_agg_avg"],
	}, {
		"time spent submitting metrics this period",
		m["submit_metrics_sum"],
	}, {
		"number of goroutines",
		m["sys.NumGoroutine"],
	}, {
		"time spent in GC",
		m["sys.PauseTotalNs"],
	},
}
for _, nameValue := range example {
	var result string
	if nameValue.Value == float64(0) {
		result = "NOT present"
	} else {
		result = "present"
	}
	fmt.Println(nameValue.Name, result)
}
ms.Stop()
Output:

total range splits during the process lifetime present
range splits in this period present
some_ipc 99.9th percentile present
some_ipc max present
some_ipc calls this period present
some_ipc calls during the process lifetime present
some_ipc total latency this period present
some_ipc mean this period present
some_ipc aggregate man present
time spent submitting metrics this period present
number of goroutines present
time spent in GC present

func NewMetricSystem

func NewMetricSystem(interval time.Duration, sysStats bool) *MetricSystem

NewMetricSystem returns a new metric system that collects and broadcasts metrics after each interval.

func (*MetricSystem) Counter

func (ms *MetricSystem) Counter(name string, amount uint64)

Counter is used for recording a running count of the total occurrences of a particular event. A rate is also exported for the amount that a counter has increased during an interval of this MetricSystem.

func (*MetricSystem) DeregisterGaugeFunc

func (ms *MetricSystem) DeregisterGaugeFunc(name string)

DeregisterGaugeFunc deregisters a function for the <name> metric.

func (*MetricSystem) Histogram

func (ms *MetricSystem) Histogram(name string, value float64)

Histogram is used for generating rich metrics, such as percentiles, from periodically occurring continuous values.

func (*MetricSystem) RegisterGaugeFunc

func (ms *MetricSystem) RegisterGaugeFunc(name string, f func() float64)

RegisterGaugeFunc registers a function to be called at each interval whose return value will be used to populate the <name> metric.

func (*MetricSystem) Start

func (ms *MetricSystem) Start()

Start spawns a goroutine for merging metrics into caches from metric submitters, and a reaper goroutine that harvests metrics at the default interval of every 60 seconds.

func (*MetricSystem) StartTimer

func (ms *MetricSystem) StartTimer(name string) TimerToken

StartTimer begins a timer and returns a token which is required for halting the timer. This allows for concurrent timings under the same name.

func (*MetricSystem) Stop

func (ms *MetricSystem) Stop()

Stop shuts down a MetricSystem

func (*MetricSystem) StopTimer

func (ms *MetricSystem) StopTimer(token TimerToken) time.Duration

StopTimer takes a token given by StartTimer, stops the timer, submits a Histogram of its duration in nanoseconds, and returns its duration in nanoseconds.

func (*MetricSystem) SubscribeToProcessedMetrics

func (ms *MetricSystem) SubscribeToProcessedMetrics(
	metricStream chan *ProcessedMetricSet)

SubscribeToProcessedMetrics registers a channel to receive ProcessedMetricSets periodically generated by reaper at each interval.

func (*MetricSystem) SubscribeToRawMetrics

func (ms *MetricSystem) SubscribeToRawMetrics(metricStream chan *RawMetricSet)

SubscribeToRawMetrics registers a channel to receive RawMetricSets periodically generated by reaper at each interval.

func (*MetricSystem) UnsubscribeFromProcessedMetrics

func (ms *MetricSystem) UnsubscribeFromProcessedMetrics(
	metricStream chan *ProcessedMetricSet)

UnsubscribeFromProcessedMetrics registers a channel to receive ProcessedMetricSets periodically generated by reaper at each interval.

func (*MetricSystem) UnsubscribeFromRawMetrics

func (ms *MetricSystem) UnsubscribeFromRawMetrics(
	metricStream chan *RawMetricSet)

UnsubscribeFromRawMetrics registers a channel to receive RawMetricSets periodically generated by reaper at each interval.

type ProcessedMetricSet

type ProcessedMetricSet struct {
	Time    time.Time
	Metrics map[string]float64
}

ProcessedMetricSet contains human-readable metrics that may also be suitable for storage in time-series databases.

type RawMetricSet

type RawMetricSet struct {
	Time       time.Time
	Counters   map[string]uint64
	Rates      map[string]uint64
	Histograms map[string]map[int16]*uint64
	Gauges     map[string]float64
}

RawMetricSet contains metrics in a form that supports generation of percentiles and other rich statistics.

type TimerToken

type TimerToken struct {
	Name  string
	ID    uint32
	Start time.Time
}

TimerToken facilitates concurrent timings of durations of the same label.

Jump to

Keyboard shortcuts

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