reinh / statsd

A Ruby Statsd client that isn't a direct port of the Python example code. Because Ruby isn't Python.
MIT License
411 stars 154 forks source link

New statsd interceptor for wrapping instances #40

Closed raykrueger closed 11 years ago

raykrueger commented 11 years ago

This is a pattern I've used in one of the apps I have and figured it might be a useful contribution.

To use it simply wrap any object and call methods on it as normal.

For instance, if you wanted to time every call to a redis client:

require 'statsd/interceptor'
require 'redis'

statsd = Statsd.new('localhost', 1234)
redis = Statsd::Interceptor.new(Redis.current, statsd)

redis.set "blah", true
redis.get "blah"

Would produce timings such as: "Redis.get:1|ms" and "Redis.set:1|ms"

If the target raises any errors an "errors" counter is incremented: "Redis.get.errors:1|c" "Redis.set.errors:1|c"

reinh commented 11 years ago

We try to keep ruby-statsd as lightweight as possible and this is definitely non-core functionality. I think it would be better (and quite easy) to package it as its own gem that depends on ruby-statsd. Perhaps we should create a wiki page that links to useful extensions like rack-statsd and this (see #41).

Roping in @raggi

raykrueger commented 11 years ago

Yep, totally understood. Like I said, it's a pattern I've gotten a lot of use out of and it's not tied to any outside tech, like rack. So I figured I'd throw it out there if you're interested.

On Fri, Apr 12, 2013 at 10:12 AM, Rein Henrichs notifications@github.com wrote:

We try to keep ruby-statsd as lightweight as possible and this is definitely non-core functionality. I think it would be better (and quite easy) to package it as its own gem that depends on ruby-statsd. Perhaps we should create a wiki page that links to useful extensions like rack-statsd and this.

Reply to this email directly or view it on GitHub: https://github.com/reinh/statsd/pull/40#issuecomment-16298421

reinh commented 11 years ago

@raykrueger I do think it's a cool pattern (although I have some performance concerns that may be partially alleviated by using a low sample rate), but I also don't think it's right for core statsd-ruby. I would love it if you made it a gem and would be happy to promote it from the wiki. What say you? :D

raykrueger commented 11 years ago

yep yep. I'll throw that together. Thanks!