-
Notifications
You must be signed in to change notification settings - Fork 118
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 tag support in statsd reporter | Upgrade go-statsd-client #163
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,21 +21,26 @@ | |
package main | ||
|
||
import ( | ||
"io" | ||
"log" | ||
"math/rand" | ||
"time" | ||
|
||
"github.com/cactus/go-statsd-client/statsd" | ||
"github.com/uber-go/tally" | ||
statsdreporter "github.com/uber-go/tally/statsd" | ||
|
||
"github.com/cactus/go-statsd-client/statsd" | ||
) | ||
|
||
// To view statsd emitted metrics locally you can use | ||
// netcat with "nc 8125 -l -u" | ||
func main() { | ||
statter, err := statsd.NewBufferedClient("127.0.0.1:8125", | ||
"stats", 100*time.Millisecond, 1440) | ||
statter, err := statsd.NewClientWithConfig(&statsd.ClientConfig{ | ||
Address: "127.0.0.1:8125", | ||
Prefix: "stats", | ||
FlushInterval: 100 * time.Millisecond, | ||
FlushBytes: 1440, | ||
TagFormat: statsd.InfixComma, | ||
}) | ||
if err != nil { | ||
log.Fatalf("could not create statsd client: %v", err) | ||
} | ||
|
@@ -48,9 +53,15 @@ func main() { | |
Tags: map[string]string{}, | ||
Reporter: r, | ||
}, 1*time.Second) | ||
defer closer.Close() | ||
|
||
counter := scope.Counter("test-counter") | ||
defer func(closer io.Closer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
_ = closer.Close() | ||
}(closer) | ||
|
||
counter := scope.Tagged(map[string]string{ | ||
"host": "local", | ||
"env": "dev", | ||
}).Counter("test-counter") | ||
|
||
gauge := scope.Gauge("test-gauge") | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,9 +26,8 @@ import ( | |
"strconv" | ||
"time" | ||
|
||
"github.com/uber-go/tally" | ||
|
||
"github.com/cactus/go-statsd-client/statsd" | ||
"github.com/uber-go/tally" | ||
) | ||
|
||
const ( | ||
|
@@ -74,15 +73,15 @@ func NewReporter(statsd statsd.Statter, opts Options) tally.StatsReporter { | |
} | ||
|
||
func (r *cactusStatsReporter) ReportCounter(name string, tags map[string]string, value int64) { | ||
r.statter.Inc(name, value, r.sampleRate) | ||
r.statter.Inc(name, value, r.sampleRate, getStatsdTagPairs(tags)...) | ||
} | ||
|
||
func (r *cactusStatsReporter) ReportGauge(name string, tags map[string]string, value float64) { | ||
r.statter.Gauge(name, int64(value), r.sampleRate) | ||
r.statter.Gauge(name, int64(value), r.sampleRate, getStatsdTagPairs(tags)...) | ||
} | ||
|
||
func (r *cactusStatsReporter) ReportTimer(name string, tags map[string]string, interval time.Duration) { | ||
r.statter.TimingDuration(name, interval, r.sampleRate) | ||
r.statter.TimingDuration(name, interval, r.sampleRate, getStatsdTagPairs(tags)...) | ||
} | ||
|
||
func (r *cactusStatsReporter) ReportHistogramValueSamples( | ||
|
@@ -97,7 +96,7 @@ func (r *cactusStatsReporter) ReportHistogramValueSamples( | |
fmt.Sprintf("%s.%s-%s", name, | ||
r.valueBucketString(bucketLowerBound), | ||
r.valueBucketString(bucketUpperBound)), | ||
samples, r.sampleRate) | ||
samples, r.sampleRate, getStatsdTagPairs(tags)...) | ||
} | ||
|
||
func (r *cactusStatsReporter) ReportHistogramDurationSamples( | ||
|
@@ -112,7 +111,7 @@ func (r *cactusStatsReporter) ReportHistogramDurationSamples( | |
fmt.Sprintf("%s.%s-%s", name, | ||
r.durationBucketString(bucketLowerBound), | ||
r.durationBucketString(bucketUpperBound)), | ||
samples, r.sampleRate) | ||
samples, r.sampleRate, getStatsdTagPairs(tags)...) | ||
} | ||
|
||
func (r *cactusStatsReporter) valueBucketString( | ||
|
@@ -148,9 +147,17 @@ func (r *cactusStatsReporter) Reporting() bool { | |
} | ||
|
||
func (r *cactusStatsReporter) Tagging() bool { | ||
return false | ||
return true | ||
} | ||
|
||
func (r *cactusStatsReporter) Flush() { | ||
// no-op | ||
} | ||
|
||
func getStatsdTagPairs(tags map[string]string) []statsd.Tag { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
tagPairs := make([]statsd.Tag, 0, len(tags)) | ||
for k, v := range tags { | ||
tagPairs = append(tagPairs, statsd.Tag{k, v}) | ||
} | ||
return tagPairs | ||
} |
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.
This is deprecated now