Documentation
¶
Index ¶
- Variables
- func GraphiteProtocol(ms *ProcessedMetricSet) []byte
- func OpenTSDBProtocol(ms *ProcessedMetricSet) []byte
- func PrintBenchmark(name string, concurrency uint, op func())
- 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) SpecifyPercentiles(percentiles map[string]float64)
- func (ms *MetricSystem) Start()
- func (ms *MetricSystem) StartTimer(name string) TimerToken
- func (ms *MetricSystem) Stop()
- 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 Submitter
- 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 ¶
func GraphiteProtocol ¶
func GraphiteProtocol(ms *ProcessedMetricSet) []byte
GraphiteProtocol generates a wire representation of a ProcessedMetricSet for submission to a Graphite Carbon instance using the plaintext protocol.
func OpenTSDBProtocol ¶
func OpenTSDBProtocol(ms *ProcessedMetricSet) []byte
OpenTSDBProtocol generates a wire representation of a ProcessedMetricSet for submission to an OpenTSDB instance.
func PrintBenchmark ¶
PrintBenchmark will run the provided function at the specified concurrency, time the operation, and once per second write the following information to standard out:
2014-08-09 17:44:57 -0400 EDT raft_AppendLogEntries_count: 16488 raft_AppendLogEntries_max: 3.982478339757623e+07 raft_AppendLogEntries_99.99: 3.864778314316012e+07 raft_AppendLogEntries_99.9: 3.4366224772310276e+06 raft_AppendLogEntries_99: 2.0228126576114902e+06 raft_AppendLogEntries_50: 469769.7083161708 raft_AppendLogEntries_min: 129313.15075081984 raft_AppendLogEntries_sum: 9.975892639594093e+09 raft_AppendLogEntries_avg: 605039.5827022133 raft_AppendLogEntries_agg_avg: 618937 raft_AppendLogEntries_agg_count: 121095 raft_AppendLogEntries_agg_sum: 7.4950269894e+10 sys.Alloc: 997328 sys.NumGC: 1115 sys.PauseTotalNs: 2.94946542e+08 sys.NumGoroutine: 26
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)
timeToken.Stop()
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) SpecifyPercentiles ¶
func (ms *MetricSystem) SpecifyPercentiles(percentiles map[string]float64)
SpecifyPercentiles allows users to override the default collected and reported percentiles.
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) 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.
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 Submitter ¶
type Submitter struct {
DestinationNetwork string
DestinationAddress string
// contains filtered or unexported fields
}
Submitter encapsulates the state of a metric submitter.
func NewSubmitter ¶
func NewSubmitter(metricSystem *MetricSystem, serializer func(*ProcessedMetricSet) []byte, destinationNetwork string, destinationAddress string) *Submitter
NewSubmitter creates a Submitter that receives metrics off of a specified metric channel, serializes them using the provided serialization function, and attempts to send them to the specified destination.
type TimerToken ¶
type TimerToken struct {
Name string
Start time.Time
MetricSystem *MetricSystem
}
TimerToken facilitates concurrent timings of durations of the same label.
func (*TimerToken) Stop ¶
func (tt *TimerToken) Stop() time.Duration
Stop stops a timer given by StartTimer, submits a Histogram of its duration in nanoseconds, and returns its duration in nanoseconds.