Documentation ¶
Index ¶
- Variables
- type MetricSystem
- func (ms *MetricSystem) Counter(name string, amount uint64)
- func (ms *MetricSystem) DeregisterGaugeFunc(name string)
- func (ms *MetricSystem) Histogram(name string, value float64)
- func (ms *MetricSystem) RegisterGaugeFunc(name string, f func() float64)
- func (ms *MetricSystem) Start()
- func (ms *MetricSystem) StartTimer(name string) TimerToken
- func (ms *MetricSystem) Stop()
- func (ms *MetricSystem) StopTimer(token TimerToken) time.Duration
- func (ms *MetricSystem) SubscribeToProcessedMetrics(metricStream chan *ProcessedMetricSet)
- func (ms *MetricSystem) SubscribeToRawMetrics(metricStream chan *RawMetricSet)
- func (ms *MetricSystem) UnsubscribeFromProcessedMetrics(metricStream chan *ProcessedMetricSet)
- func (ms *MetricSystem) UnsubscribeFromRawMetrics(metricStream chan *RawMetricSet)
- type ProcessedMetricSet
- type RawMetricSet
- type TimerToken
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Metrics = NewMetricSystem(60*time.Second, true)
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) 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 ¶
ProcessedMetricSet contains human-readable metrics that may also be suitable for storage in time-series databases.