Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

move to use scales instead of pystatsd

  • Loading branch information...
commit 622b2fe41b9265e3f756aa920353ed8916038050 1 parent f58102c
Ubuntu authored
Showing with 40 additions and 22 deletions.
  1. +37 −19 sentry_graphite/__init__.py
  2. +3 −3 setup.py
View
56 sentry_graphite/__init__.py
@@ -6,27 +6,36 @@
:license: Apache License 2.0, see LICENSE for more details.
"""
+import logging
from django import forms
from sentry.conf import settings
-from sentry.plugins import Plugin
+from sentry.plugins import Plugin, register
+from greplin import scales
+from greplin.scales import graphite
-from pystatsd import Client
+# from pystatsd import Client
NOTSET = object()
class GraphiteConfigurationForm(forms.Form):
- host = forms.CharField(max_length=64, widget=forms.TextInput(attrs={
- 'placeholder': 'graphite.local',
- }))
+ host = forms.CharField(max_length=64, required=False,
+ help_text="the host to which your scales will connect",
+ widget=forms.TextInput(attrs={
+ 'placeholder': '127.0.0.1',
+ })
+ )
port = forms.IntegerField(max_value=65535, widget=forms.TextInput(attrs={
- 'placeholder': '8125',
+ 'placeholder': '2003',
}))
prefix = forms.CharField(max_length=64, widget=forms.TextInput(attrs={
'placeholder': 'sentry',
}))
+pusher = None
+
+
class GraphiteProcessor(Plugin):
title = 'Graphite'
conf_key = 'graphite'
@@ -38,17 +47,17 @@ def __init__(self, min_level=NOTSET, include_loggers=NOTSET, exclude_loggers=NOT
super(GraphiteProcessor, self).__init__(*args, **kwargs)
if min_level is NOTSET:
- min_level = settings.GRAPIHTE_LEVEL
+ min_level = getattr(settings, 'GRAPHITE_LEVEL', logging.DEBUG)
if include_loggers is NOTSET:
- include_loggers = settings.GRAPHITE_INCLUDE_LOGGERS
+ include_loggers = getattr(settings, 'GRAPHITE_INCLUDE_LOGGERS', None)
if exclude_loggers is NOTSET:
- exclude_loggers = settings.GRAPHITE_EXCLUDE_LOGGERS
+ exclude_loggers = getattr(settings, 'GRAPHITE_EXCLUDE_LOGGERS', None)
if host is NOTSET:
- host = settings.GRAPHITE_HOST
+ host = getattr(settings, 'GRAPHITE_HOST', '127.0.0.1')
if port is NOTSET:
- port = settings.GRAPHITE_PORT
+ port = getattr(settings, 'GRAPHITE_PORT', 2444)
if prefix is NOTSET:
- prefix = settings.GRAPHITE_PREFIX
+ prefix = getattr(settings, 'GRAPHITE_PREFIX', 'sentry')
self.min_level = min_level
self.include_loggers = include_loggers
@@ -57,18 +66,26 @@ def __init__(self, min_level=NOTSET, include_loggers=NOTSET, exclude_loggers=NOT
self.port = port
self.prefix = prefix
- self.client = Client(host=self.host, port=self.port)
+ # self.client = Client(host=self.host, port=self.port)
+ self.stats = scales.collection('/sentry', scales.IntStat('totalEvents'),
+ scales.IntDictStat('eventsByTop'))
+ global pusher
+ if pusher is None:
+ pusher = graphite.GraphitePeriodicPusher(self.host, self.port, self.prefix)
+ pusher.start()
def record_event(self, group, event, fail_silently=True):
- project = group.project
+ # project = group.project
- host = self.get_option('host', project) or self.host
- port = self.get_option('port', project) or self.port
- prefix = self.get_option('prefix', project) or self.prefix
+ # host = self.get_option('host', project) or self.host
+ # port = self.get_option('port', project) or self.port
+ # prefix = self.get_option('prefix', project) or self.prefix
- key = '.'.join([prefix, event.message_top])
+ # key = '.'.join([prefix, event.message_top()])
- self.client.increment(key)
+ # self.client.increment(key)
+ self.stats.totalEvents += 1
+ self.stats.eventsByTop[event.message_top()] += 1
def should_record(self, group, event):
project = group.project
@@ -99,3 +116,4 @@ def post_process(self, group, event, is_new, is_sample, **kwargs):
self.record_event(group, event)
+register(GraphiteProcessor)
View
6 setup.py
@@ -18,12 +18,12 @@
install_requires = [
'sentry>=2.1.0',
- 'pystatsd',
+ 'scales',
]
setup(
name='sentry-graphite',
- version='0.1.0',
+ version='0.2.0',
author='DISQUS',
author_email='opensource@disqus.com',
url='http://github.com/disqus/sentry-graphite',
@@ -41,5 +41,5 @@
'Operating System :: OS Independent',
'Topic :: Software Development'
],
- keywords='sentry graphite',
+ keywords='sentry graphite scales',
)
Please sign in to comment.
Something went wrong with that request. Please try again.