-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using new metrics lib. #38
Open
dukelion
wants to merge
8
commits into
master
Choose a base branch
from
Metrics-rewrite
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e4e68b7
Removing rate parameter, change stats name to slice. Utilize armon/go…
dukelion 9c13c66
Added glide entry for armon/go-metrics
dukelion 46f7d5b
Reverted AsStatField func, fixed missed Inc() calls
dukelion e6d90fe
More fixes
dukelion 3b31146
Reverted dockerclient import
dukelion 2ebe908
Fixed Inc() calls for docker client
719bb91
Improving stats calls
dukelion 3fa6b07
Added tags, moved StatsdConfig definition
dukelion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package stats | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"strings" | ||
"time" | ||
|
||
"github.com/armon/go-metrics" | ||
"gopkg.in/inconshreveable/log15.v2" | ||
) | ||
|
||
func NewMetricsStatter(config Config) Statter { | ||
inm := metrics.NewInmemSink(10*time.Second, time.Minute) | ||
metrics.DefaultInmemSignal(inm) | ||
|
||
var fanout metrics.FanoutSink | ||
|
||
if config.Statsd != nil && config.Statsd.StatsdUdpTarget != "" { | ||
sink, err := metrics.NewStatsdSink(config.Statsd.StatsdUdpTarget) | ||
if err != nil { | ||
log15.Error("Couldn't create statsd reporter", "err", err) | ||
} | ||
fanout = append(fanout, sink) | ||
} | ||
prefix := "iron" | ||
if config.Statsd != nil && len(config.Statsd.Prefix) > 0 { | ||
prefix = config.Statsd.Prefix + ".iron" | ||
} | ||
metricsConfig := metrics.DefaultConfig(prefix) | ||
metricsConfig.EnableRuntimeMetrics = false // Use another metrics instance for runtime stats reporting | ||
metricsConfig.EnableHostname = false | ||
|
||
m := new(MetricsStatter) | ||
m.hostname = whoami() | ||
m.servicePrefix = path.Base(os.Args[0]) | ||
|
||
if len(fanout) > 0 { | ||
if !config.NoHostname { | ||
metricsConfig.ServiceName = strings.Join([]string{prefix, m.servicePrefix, m.hostname}, ".") | ||
} | ||
fanout = append(fanout, inm) | ||
metrics.NewGlobal(metricsConfig, fanout) | ||
} else { | ||
metrics.NewGlobal(metricsConfig, inm) | ||
} | ||
|
||
if config.GCStats >= 0 { | ||
if config.GCStats == 0 { | ||
config.GCStats = 1 | ||
} | ||
metricsConfig.EnableRuntimeMetrics = true | ||
metricsConfig.ProfileInterval = time.Duration(config.Interval * float64(time.Second)) | ||
if len(fanout) > 0 { | ||
metricsConfig.ServiceName = strings.Join([]string{prefix, m.servicePrefix, m.hostname}, ".") | ||
metrics.New(metricsConfig, fanout) | ||
} else { | ||
metrics.New(metricsConfig, inm) | ||
} | ||
} | ||
|
||
log15.Info("Statter configured", "servicePrefix", m.servicePrefix) | ||
|
||
return m | ||
} | ||
|
||
type MetricsStatter struct { | ||
hostname string | ||
servicePrefix string | ||
} | ||
|
||
func (m *MetricsStatter) template(stat ...string) []string { | ||
newstat := []string{m.servicePrefix} | ||
for _, token := range stat { | ||
switch token { | ||
case "@hostname": | ||
newstat = append(newstat, m.hostname) | ||
default: | ||
newstat = append(newstat, token) | ||
} | ||
} | ||
return newstat | ||
} | ||
|
||
func (m *MetricsStatter) Inc(value int64, stat ...string) { | ||
newstat := m.template(stat...) | ||
metrics.IncrCounter(newstat, float32(value)) | ||
} | ||
func (m *MetricsStatter) Gauge(value int64, stat ...string) { | ||
newstat := m.template(stat...) | ||
metrics.SetGauge(newstat, float32(value)) | ||
} | ||
func (m *MetricsStatter) Measure(value int64, stat ...string) { | ||
newstat := m.template(stat...) | ||
metrics.AddSample(newstat, float32(value)) | ||
} | ||
func (m *MetricsStatter) Time(value time.Duration, stat ...string) { | ||
newstat := m.template(stat...) | ||
metrics.AddSample(newstat, float32(value.Nanoseconds()/1e6)) //Report ms to statsd | ||
} | ||
func (m *MetricsStatter) NewTimer(stat ...string) *Timer { | ||
return newTimer(m, m.template(stat...)...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package stats | ||
|
||
import ( | ||
"time" | ||
|
||
"gopkg.in/inconshreveable/log15.v2" | ||
) | ||
|
||
type MultiStatter struct { | ||
statters []Statter | ||
} | ||
|
||
func NewMultiStatter(config Config) Statter { | ||
s := new(MultiStatter) | ||
|
||
var reporters []reporter | ||
if config.StatHat != nil && config.StatHat.Email != "" { | ||
reporters = append(reporters, config.StatHat) | ||
} | ||
|
||
if config.NewRelic != nil && config.NewRelic.LicenseKey != "" { | ||
// NR wants version? | ||
// can get it out of the namespace? roll it here? | ||
reporters = append(reporters, NewNewRelicReporter("1.0", config.NewRelic.LicenseKey)) | ||
} | ||
|
||
if config.Log15 != nil { | ||
reporters = append(reporters, NewLogReporter()) | ||
} | ||
|
||
if len(reporters) > 0 { | ||
ag := newAggregator(reporters) | ||
s.statters = append(s.statters, ag) | ||
go func() { | ||
for range time.Tick(time.Duration(config.Interval * float64(time.Second))) { | ||
ag.report(nil) | ||
} | ||
}() | ||
} | ||
|
||
if config.Statsd != nil && config.Statsd.StatsdUdpTarget != "" { | ||
std, err := NewStatsd(config.Statsd) | ||
if err == nil { | ||
s.statters = append(s.statters, std) | ||
} else { | ||
log15.Error("Couldn't create statsd reporter", "err", err) | ||
} | ||
} | ||
|
||
if len(reporters) == 0 && config.Statsd == nil && config.History == 0 { | ||
return &NilStatter{} | ||
} | ||
|
||
if config.GCStats >= 0 { | ||
if config.GCStats == 0 { | ||
config.GCStats = 1 | ||
} | ||
go StartReportingMemoryAndGC(s, time.Duration(config.GCStats)*time.Second) | ||
} | ||
|
||
return s | ||
} | ||
|
||
func (s *MultiStatter) Inc(value int64, stat ...string) { | ||
for _, st := range s.statters { | ||
st.Inc(value, stat...) | ||
} | ||
} | ||
|
||
func (s *MultiStatter) Gauge(value int64, stat ...string) { | ||
for _, st := range s.statters { | ||
st.Gauge(value, stat...) | ||
} | ||
} | ||
|
||
func (s *MultiStatter) Measure(value int64, stat ...string) { | ||
for _, st := range s.statters { | ||
st.Measure(value, stat...) | ||
} | ||
} | ||
|
||
func (s *MultiStatter) Time(value time.Duration, stat ...string) { | ||
for _, st := range s.statters { | ||
st.Time(value, stat...) | ||
} | ||
} | ||
|
||
func (s *MultiStatter) NewTimer(stat ...string) *Timer { | ||
return newTimer(s, stat...) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
time.Duration(config.Interval) * time.Second
instead oftime.Duration(config.Interval * float64(time.Second))
to omitfloat64()
?