Skip to content

Commit

Permalink
Export all the Config variables
Browse files Browse the repository at this point in the history
  • Loading branch information
armon committed Aug 9, 2013
1 parent 78924a3 commit 2cdce68
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
16 changes: 8 additions & 8 deletions start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 2cdce68

Please sign in to comment.