mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-15 14:03:02 +00:00
Add statsd to the base JupyterHub app
Not actually emitting any metrics yet
This commit is contained in:
@@ -12,6 +12,7 @@ import signal
|
|||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import threading
|
import threading
|
||||||
|
import statsd
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from distutils.version import LooseVersion as V
|
from distutils.version import LooseVersion as V
|
||||||
from getpass import getuser
|
from getpass import getuser
|
||||||
@@ -59,6 +60,10 @@ from .utils import (
|
|||||||
from .auth import Authenticator, PAMAuthenticator
|
from .auth import Authenticator, PAMAuthenticator
|
||||||
from .spawner import Spawner, LocalProcessSpawner
|
from .spawner import Spawner, LocalProcessSpawner
|
||||||
|
|
||||||
|
# For faking stats
|
||||||
|
from .emptyclass import EmptyClass
|
||||||
|
|
||||||
|
|
||||||
common_aliases = {
|
common_aliases = {
|
||||||
'log-level': 'Application.log_level',
|
'log-level': 'Application.log_level',
|
||||||
'f': 'JupyterHub.config_file',
|
'f': 'JupyterHub.config_file',
|
||||||
@@ -492,6 +497,22 @@ class JupyterHub(Application):
|
|||||||
help="Extra log handlers to set on JupyterHub logger",
|
help="Extra log handlers to set on JupyterHub logger",
|
||||||
).tag(config=True)
|
).tag(config=True)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def statsd(self):
|
||||||
|
if hasattr(self, '_statsd'):
|
||||||
|
return self._statsd
|
||||||
|
if self.statsd_host:
|
||||||
|
self._statsd = statsd.StatsClient(
|
||||||
|
self.statsd_host,
|
||||||
|
self.statsd_port,
|
||||||
|
self.statsd_prefix
|
||||||
|
)
|
||||||
|
return self._statsd
|
||||||
|
else:
|
||||||
|
# return an empty mock object!
|
||||||
|
self._statsd = EmptyClass()
|
||||||
|
return self._statsd
|
||||||
|
|
||||||
def init_logging(self):
|
def init_logging(self):
|
||||||
# This prevents double log messages because tornado use a root logger that
|
# This prevents double log messages because tornado use a root logger that
|
||||||
# self.log is a child of. The logging module dipatches log messages to a log
|
# self.log is a child of. The logging module dipatches log messages to a log
|
||||||
|
13
jupyterhub/emptyclass.py
Normal file
13
jupyterhub/emptyclass.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
"""
|
||||||
|
Simple empty class that returns itself for all functions called on it.
|
||||||
|
This allows us to call any method of any name on this, and it'll return another
|
||||||
|
instance of itself that'll allow any method to be called on it.
|
||||||
|
|
||||||
|
Primarily used to mock out the statsd client when statsd is not being used
|
||||||
|
"""
|
||||||
|
class EmptyClass:
|
||||||
|
def empty_function(self, *args, **kwargs):
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __getattr__(self, attr):
|
||||||
|
return self.empty_function
|
@@ -2,5 +2,6 @@ traitlets>=4.1
|
|||||||
tornado>=4.1
|
tornado>=4.1
|
||||||
jinja2
|
jinja2
|
||||||
pamela
|
pamela
|
||||||
|
statsd
|
||||||
sqlalchemy>=1.0
|
sqlalchemy>=1.0
|
||||||
requests
|
requests
|
||||||
|
Reference in New Issue
Block a user