Skip to content
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

add concurrencyInUse metric to graphite #122

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions plugins/graphite_aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

var makeTimerFunc = func() interface{} { return metrics.NewTimer() }
var makeCounterFunc = func() interface{} { return metrics.NewCounter() }
var makeGaugeFunc = func() interface{} { return metrics.NewGaugeFloat64() }

// GraphiteCollector fulfills the metricCollector interface allowing users to ship circuit
// stats to a graphite backend. To use users must call InitializeGraphiteCollector before
Expand All @@ -32,6 +33,7 @@ type GraphiteCollector struct {
fallbackFailuresPrefix string
totalDurationPrefix string
runDurationPrefix string
concurrencyInUsePrefix string
}

// GraphiteCollectorConfig provides configuration that the graphite client will need.
Expand Down Expand Up @@ -69,6 +71,7 @@ func NewGraphiteCollector(name string) metricCollector.MetricCollector {
fallbackFailuresPrefix: name + ".fallbackFailures",
totalDurationPrefix: name + ".totalDuration",
runDurationPrefix: name + ".runDuration",
concurrencyInUsePrefix: name + ".concurrencyInUse",
}
}

Expand All @@ -91,6 +94,14 @@ func (g *GraphiteCollector) updateTimerMetric(prefix string, dur time.Duration)
c.Update(dur)
}

func (g *GraphiteCollector) updateGaugeMetric(prefix string, data float64) {
c, ok := metrics.GetOrRegister(prefix, makeGaugeFunc()).(metrics.GaugeFloat64)
if !ok {
return
}
c.Update(data)
}

func (g *GraphiteCollector) Update(r metricCollector.MetricResult) {
g.incrementCounterMetric(g.attemptsPrefix, r.Attempts)
g.incrementCounterMetric(g.errorsPrefix, r.Errors)
Expand All @@ -103,6 +114,7 @@ func (g *GraphiteCollector) Update(r metricCollector.MetricResult) {
g.incrementCounterMetric(g.fallbackFailuresPrefix, r.FallbackFailures)
g.updateTimerMetric(g.totalDurationPrefix, r.TotalDuration)
g.updateTimerMetric(g.runDurationPrefix, r.RunDuration)
g.updateGaugeMetric(g.concurrencyInUsePrefix, r.ConcurrencyInUse)
}

// Reset is a noop operation in this collector.
Expand Down