mirror of https://github.com/apache/superset.git
Adding some STATSD logging (#2715)
This commit is contained in:
parent
841e18a08c
commit
7c5f61d6a6
|
@ -17,6 +17,11 @@ from collections import OrderedDict
|
|||
from dateutil import tz
|
||||
from flask_appbuilder.security.manager import AUTH_DB
|
||||
|
||||
from superset.stats_logger import DummyStatsLogger
|
||||
|
||||
# Realtime stats logger, a StatsD implementation exists
|
||||
STATS_LOGGER = DummyStatsLogger()
|
||||
|
||||
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
DATA_DIR = os.path.join(os.path.expanduser('~'), '.superset')
|
||||
if not os.path.exists(DATA_DIR):
|
||||
|
|
|
@ -13,7 +13,6 @@ revision = 'a6c18f869a4e'
|
|||
down_revision = '979c03af3341'
|
||||
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column(
|
||||
'query',
|
||||
|
|
|
@ -42,6 +42,7 @@ install_aliases()
|
|||
from urllib import parse # noqa
|
||||
|
||||
config = app.config
|
||||
stats_logger = config.get('STATS_LOGGER')
|
||||
metadata = Model.metadata # pylint: disable=no-member
|
||||
|
||||
|
||||
|
@ -751,6 +752,7 @@ class Log(Model):
|
|||
params = json.dumps(d)
|
||||
except:
|
||||
pass
|
||||
stats_logger.incr(f.__name__)
|
||||
value = f(*args, **kwargs)
|
||||
|
||||
sesh = db.session()
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
|
||||
class BaseStatsLogger(object):
|
||||
"""Base class for logging realtime events"""
|
||||
|
||||
def __init__(self, prefix='superset'):
|
||||
self.prefix = prefix
|
||||
|
||||
def key(self, key):
|
||||
if self.prefix:
|
||||
return self.prefix + key
|
||||
return key
|
||||
|
||||
def incr(self, key):
|
||||
"""Increment a counter"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def decr(self, key):
|
||||
"""Decrement a counter"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def gauge(self, key):
|
||||
"""Setup a gauge"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class DummyStatsLogger(BaseStatsLogger):
|
||||
|
||||
def incr(self, key):
|
||||
pass
|
||||
|
||||
def decr(self, key):
|
||||
pass
|
||||
|
||||
def gauge(self, key):
|
||||
pass
|
||||
|
||||
|
||||
try:
|
||||
from statsd import StatsClient
|
||||
|
||||
class StatsdStatsLogger(BaseStatsLogger):
|
||||
def __init__(self, host, port, prefix='superset'):
|
||||
self.client = StatsClient(
|
||||
host=host,
|
||||
port=port,
|
||||
prefix=prefix)
|
||||
|
||||
def incr(self, key):
|
||||
self.client.incr(key)
|
||||
|
||||
def decr(self, key):
|
||||
self.client.decr(key)
|
||||
|
||||
def gauge(self, key):
|
||||
self.client.gauge(key)
|
||||
except Exception as e:
|
||||
pass
|
Loading…
Reference in New Issue