Skip to content

Commit

Permalink
Graphite support
Browse files Browse the repository at this point in the history
  • Loading branch information
hexylena committed Apr 24, 2017
1 parent aa024f6 commit c9087fe
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 0 deletions.
10 changes: 10 additions & 0 deletions config/galaxy.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,16 @@ use_interactive = True
#statsd_port=8125
#statsd_prefix=galaxy

# Log to graphite
# Graphite is an external statistics aggregator (https://github.com/graphite-project/carbon)
# Enabling the following options will cause galaxy to log request timing and
# other statistics to the configured graphite instance. The graphite_prefix is
# useful if you are running multiple Galaxy instances and want to segment
# statistics between them within the same aggregator.
#graphite_host=
#graphite_port=2003
#graphite_prefix=galaxy

# -- Data Libraries

# These library upload options are described in much more detail in the wiki:
Expand Down
4 changes: 4 additions & 0 deletions lib/galaxy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,10 @@ def __init__( self, **kwargs ):
self.statsd_host = kwargs.get( 'statsd_host', '')
self.statsd_port = int( kwargs.get( 'statsd_port', 8125 ) )
self.statsd_prefix = kwargs.get( 'statsd_prefix', 'galaxy' )
# Statistics and profiling with graphite
self.graphite_host = kwargs.get( 'graphite_host', '')
self.graphite_port = int( kwargs.get( 'graphite_port', 2003 ) )
self.graphite_prefix = kwargs.get( 'graphite_prefix', 'galaxy' )
# Logging with fluentd
self.fluent_log = string_as_bool( kwargs.get( 'fluent_log', False ) )
self.fluent_host = kwargs.get( 'fluent_host', 'localhost' )
Expand Down
2 changes: 2 additions & 0 deletions lib/galaxy/dependencies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def check_raven( self ):
def check_statsd( self ):
return self.config.get("statsd_host", None) is not None

def check_graphite( self ):
return self.config.get("graphite_host", None) is not None
def check_weberror( self ):
return ( asbool( self.config["debug"] ) and
asbool( self.config["use_interactive"] ) )
Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/dependencies/conditional-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ raven
pbs_python
drmaa
statsd
graphitesend
azure-storage==0.32.0
# PyRods not in PyPI
python-ldap==2.4.27
38 changes: 38 additions & 0 deletions lib/galaxy/web/framework/middleware/graphite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
Middleware for sending request statistics to graphite
"""
from __future__ import absolute_import

import time

try:
import graphitesend
except ImportError:
# This middleware will never be used without graphite. This block allows
# unit tests pass on systems without it.
graphitesend = None


class GraphiteMiddleware(object):
"""
This middleware will log request durations to the configured graphite
instance.
"""

def __init__(self,
application,
graphite_host,
graphite_port,
graphite_prefix):
if not graphitesend:
raise ImportError("graphite middleware configured, but no graphite python module found. "
"Please install the python graphitesend module to use this functionality.")
self.application = application
self.graphite_client = graphitesend.init(graphite_server=graphite_host, graphite_port=int(graphite_port), prefix=graphite_prefix.rstrip('.'))

def __call__(self, environ, start_response):
start_time = time.time()
req = self.application(environ, start_response)
dt = int((time.time() - start_time) * 1000)
self.graphite_client.send(environ.get('controller_action_key', None) or environ.get('PATH_INFO', "NOPATH").strip('/').replace('/', '.'), dt)
return req
9 changes: 9 additions & 0 deletions lib/galaxy/webapps/galaxy/buildapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,15 @@ def wrap_in_middleware( app, global_conf, application_stack, **local_conf ):
conf.get('statsd_port', 8125),
conf.get('statsd_prefix', 'galaxy') ) )
log.debug( "Enabling 'statsd' middleware" )
# graphite request timing and profiling
graphite_host = conf.get('graphite_host', None)
if graphite_host:
from galaxy.web.framework.middleware.graphite import GraphiteMiddleware
app = wrap_if_allowed( app, stack, GraphiteMiddleware,
args=( graphite_host,
conf.get('graphite_port', 2003),
conf.get('graphite_prefix', 'galaxy') ) )
log.debug( "Enabling 'graphite' middleware" )
# If we're using remote_user authentication, add middleware that
# protects Galaxy from improperly configured authentication in the
# upstream server
Expand Down

0 comments on commit c9087fe

Please sign in to comment.