Skip to content

Instantly share code, notes, and snippets.

@raphael
Last active September 15, 2016 16:40
Show Gist options
  • Save raphael/fe330a218ff8f3840ccdcc9eea925834 to your computer and use it in GitHub Desktop.
Save raphael/fe330a218ff8f3840ccdcc9eea925834 to your computer and use it in GitHub Desktop.
// metriks is the local instance of metrics.Metrics
var metriks *metrics.Metrics
// lock synchronizes access to the metrics sink
var lock = sync.RWMutex{}
// NewMetrics initializes goa's metrics instance with the supplied
// configuration and metrics sink
func SetMetrics(m metrics.Metrics) {
lock.Lock()
defer lock.Unlock()
metriks = m
}
// AddSample adds a sample to an aggregated metric
// reporting count, min, max, mean, and std deviation
// Usage:
// AddSample([]string{"my","namespace","key"}, 15.0)
func AddSample(key []string, val float32) {
lock.RLock()
defer lock.RUnlock()
if metriks != nil {
metriks.AddSample(key, val)
}
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment