diff --git a/metrics.go b/metrics.go index 49f577b..ca73cc1 100644 --- a/metrics.go +++ b/metrics.go @@ -6,50 +6,50 @@ import ( ) func (m *Metrics) SetGauge(key []string, val float32) { - if m.enableHostname { + if m.EnableHostname { key = insert(0, m.hostName, key) } - if m.enableTypePrefix { + if m.EnableTypePrefix { key = insert(0, "gauge", key) } m.sink.SetGauge(key, val) } func (m *Metrics) EmitKey(key []string, val float32) { - if m.enableTypePrefix { + if m.EnableTypePrefix { key = insert(0, "kv", key) } m.sink.EmitKey(key, val) } func (m *Metrics) IncrCounter(key []string, val float32) { - if m.enableTypePrefix { + if m.EnableTypePrefix { key = insert(0, "counter", key) } m.sink.IncrCounter(key, val) } func (m *Metrics) AddSample(key []string, val float32) { - if m.enableTypePrefix { + if m.EnableTypePrefix { key = insert(0, "sample", key) } m.sink.AddSample(key, val) } func (m *Metrics) MeasureSince(key []string, start time.Time) { - if m.enableTypePrefix { + if m.EnableTypePrefix { key = insert(0, "timer", key) } now := time.Now() elapsed := now.Sub(start) - msec := float32(elapsed.Nanoseconds()) / float32(m.timerGranularity) + msec := float32(elapsed.Nanoseconds()) / float32(m.TimerGranularity) m.sink.AddSample(key, msec) } // Periodically collects runtime stats to publish func (m *Metrics) collectStats() { for { - time.Sleep(m.profileInterval) + time.Sleep(m.ProfileInterval) m.emitRuntimeStats() } } diff --git a/start.go b/start.go index 4fb661f..5decce7 100644 --- a/start.go +++ b/start.go @@ -8,12 +8,12 @@ import ( // Config is used to configure metrics settings type Config struct { - serviceName string // Prefixed with keys to seperate services - enableHostname bool // Enable prefixing gauge values with hostname - enableRuntimeMetrics bool // Enables profiling of runtime metrics (GC, Goroutines, Memory) - enableTypePrefix bool // Prefixes key with a type ("counter", "gauge", "timer") - timerGranularity time.Duration // Granularity of timers. - profileInterval time.Duration // Interval to profile runtime metrics + ServiceName string // Prefixed with keys to seperate services + EnableHostname bool // Enable prefixing gauge values with hostname + EnableRuntimeMetrics bool // Enables profiling of runtime metrics (GC, Goroutines, Memory) + EnableTypePrefix bool // Prefixes key with a type ("counter", "gauge", "timer") + TimerGranularity time.Duration // Granularity of timers. + ProfileInterval time.Duration // Interval to profile runtime metrics } // Metrics represents an instance of a metrics sink that can @@ -53,7 +53,7 @@ func New(conf *Config, sink MetricSink) (*Metrics, error) { met.Config = *conf // Get the hostname - if conf.enableHostname { + if conf.EnableHostname { hostName, err := os.Hostname() if err != nil { return nil, fmt.Errorf("Failed to get hostname! Got: %s", err) @@ -62,7 +62,7 @@ func New(conf *Config, sink MetricSink) (*Metrics, error) { } // Start the runtime collector - if conf.enableRuntimeMetrics { + if conf.EnableRuntimeMetrics { go met.collectStats() } return met, nil