Permalink
Browse files

statsd integration

  • Loading branch information...
1 parent 5a28ba4 commit e142b5c89503612af6fd39c2eda5e9d92bd42f60 @tarekziade tarekziade committed Mar 25, 2013
Showing with 34 additions and 8 deletions.
  1. +6 −0 monolith.ini
  2. +11 −0 monolith/web/__init__.py
  3. +5 −0 monolith/web/tests/monolith.ini
  4. +10 −8 monolith/web/views.py
  5. +2 −0 setup.py
View
@@ -3,6 +3,12 @@ use = egg:monolith.web
elasticsearch.hosts = localhost:9200
cors.origins = *
+statsd.host = localhost
+statsd.port = 8125
+statsd.rate = 1.0
+statsd.prefix = monolith.web
+
+
[server:main]
use = egg:waitress#main
host = 0.0.0.0
View
@@ -8,6 +8,7 @@
from pyramid.renderers import JSON
from pyelasticsearch import ElasticSearch
+import statsd
logger = logging.getLogger('monolith.web')
@@ -38,6 +39,16 @@ def date_adapter(obj, request):
host = settings.get('elasticsearch.host', 'http://localhost:9200')
+ # statsd settings
+ statsd_settings = {'STATSD_HOST': settings.get('statsd.host', 'localhost'),
+ 'STATSD_PORT': int(settings.get('statsd.port', 8125)),
+ 'STATSD_SAMPLE_RATE': float(settings.get('statsd.sample',
+ 1.0)),
+ 'STATSD_BUCKET_PREFIX': settings.get('statsd.prefix',
+ '')}
+
+ statsd.init_statsd(statsd_settings)
+
# XXX we need a way to lazy-inject this to the cornice views
cors_origins = settings.get('cors.origins', '*')
cors_origins = cors_origins.split(',')
@@ -3,6 +3,11 @@ use = egg:monolith.web
elasticsearch.hosts = localhost:9998
cors.origins = *
+statsd.host = localhost
+statsd.port = 8125
+statsd.rate = 1.0
+statsd.prefix = monolith.web
+
[server:main]
use = egg:waitress#main
host = 0.0.0.0
View
@@ -4,6 +4,7 @@
from colander import MappingSchema, SchemaNode, Date, Seq
from pyelasticsearch.exceptions import ElasticHttpError
+from statsd import StatsdTimer
from monolith.web import logger
@@ -45,14 +46,15 @@ def valid_json_body(request):
@es_time.post(validators=(valid_json_body,), renderer='json')
def query_es_time(request):
- query = request.validated['body']
- logger.info(query)
- try:
- return request.es.search(query, index='time_*')
- except ElasticHttpError as e:
- request.errors.status = e.status_code
- request.errors.add('body', description=e.error)
- return {}
+ with StatsdTimer('monolith.query'):
+ query = request.validated['body']
+ logger.info(query)
+ try:
+ return request.es.search(query, index='time_*')
+ except ElasticHttpError as e:
+ request.errors.status = e.status_code
+ request.errors.add('body', description=e.error)
+ return {}
heartbeat = Service(name='hb', path='/__heartbeat__')
View
@@ -9,8 +9,10 @@
'colander==1.0a2',
'cornice==0.13',
'pyelasticsearch==0.3',
+ 'statsd-client==1.0.4'
]
+
test_requires = requires + [
'coverage',
'nose',

0 comments on commit e142b5c

Please sign in to comment.