Permalink
Browse files

Initial version

  • Loading branch information...
1 parent 82a1807 commit ed66adda7dddbdfd9362fc8eab1b1bfc69e6d2e2 @aluzzardi committed May 19, 2012
Showing with 107 additions and 3 deletions.
  1. +19 −3 README.md
  2. +8 −0 riak_statsd/__init__.py
  3. +60 −0 riak_statsd/transport.py
  4. +20 −0 setup.py
View
@@ -1,4 +1,20 @@
-riak-statsd-python
-==================
+Transport proxy for instrumenting Riak clients
+==============================================
-Transport proxy for instrumenting Riak clients
+riak-statsd-python is a tiny transport proxy to instrument Riak clients written in Python.
+
+Request counters as well as response times are sent to statsd for instrumentation.
+
+Usage
+-----
+```python
+
+import riak
+import riak_statsd
+
+stats = statsd.StatsClient()
+
+db = self.db = riak.RiakClient('localhost', 1234,
+ transport_class=riak_statsd.create_proxy(riak.RiakHttpTransport, stats))
+
+```
View
@@ -0,0 +1,8 @@
+from .transport import RiakStatsdTransportProxy
+
+
+def create_proxy(transport_class, stats):
+ class TransportClass(RiakStatsdTransportProxy):
+ _stats = stats
+ _transport_class = transport_class
+ return TransportClass
View
@@ -0,0 +1,60 @@
+from riak.transports.transport import RiakTransport
+
+
+class RiakStatsdTransportProxy(RiakTransport):
+ def __init__(self, *args, **kwargs):
+ self._transport = self._transport_class(*args, **kwargs)
+
+ def _instrument(self, name):
+ self._stats.incr('riak.{0}.requests'.format(name))
+ return self._stats.timer('riak.{0}.response_time'.format(name))
+
+ def ping(self, *args, **kwargs):
+ return self._transport.ping(*args, **kwargs)
+
+ def get(self, *args, **kwargs):
+ with self._instrument('get'):
+ return self._transport.get(*args, **kwargs)
+
+ def put(self, *args, **kwargs):
+ with self._instrument('put'):
+ return self._transport.put(*args, **kwargs)
+
+ def put_new(self, *args, **kwargs):
+ with self._instrument('new'):
+ return self._transport.put_new(*args, **kwargs)
+
+ def delete(self, *args, **kwargs):
+ with self._instrument('delete'):
+ return self._transport.delete(*args, **kwargs)
+
+ def get_buckets(self, *args, **kwargs):
+ return self._transport.get_buckets(*args, **kwargs)
+
+ def get_bucket_props(self, *args, **kwargs):
+ return self._transport.get_bucket_props(*args, **kwargs)
+
+ def set_bucket_props(self, *args, **kwargs):
+ return self._transport.set_bucket_props(*args, **kwargs)
+
+ def mapred(self, *args, **kwargs):
+ with self._instrument('mapred'):
+ return self._transport.mapred(*args, **kwargs)
+
+ def set_client_id(self, *args, **kwargs):
+ return self._transport.set_client_id(*args, **kwargs)
+
+ def get_client_id(self, *args, **kwargs):
+ return self._transport.get_client_id(*args, **kwargs)
+
+ def store_file(self, *args, **kwargs):
+ with self._instrument('store_file'):
+ return self._transport.store_file(*args, **kwargs)
+
+ def get_file(self, *args, **kwargs):
+ with self._instrument('get_file'):
+ return self._transport.get_file(*args, **kwargs)
+
+ def delete_file(self, *args, **kwargs):
+ with self._instrument('delete_file'):
+ return self._transport.delete_file(*args, **kwargs)
View
@@ -0,0 +1,20 @@
+try:
+ from setuptools import setup
+except ImportError:
+ from distutils.core import setup
+
+
+setup(
+ name='riak_statsd',
+ version='0.0.1',
+ description='Transport proxy for instrumenting Riak clients',
+ author='Andrea Luzzardi',
+ author_email='andrea@luzzardi.com',
+ url='https://github.com/aluzzardi/riak-statsd-python',
+ packages=['riak_statsd'],
+ install_requires=[
+ 'statsd>=0.5.1',
+ 'riak>=1.3.0'
+ ],
+ license='MIT'
+)

0 comments on commit ed66add

Please sign in to comment.