forked from jsocol/pystatsd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
41 lines (35 loc) · 1.21 KB
/
__init__.py
File metadata and controls
41 lines (35 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from __future__ import absolute_import
import os
import socket
try:
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
try:
# This handles the case where Django >=1.5 is in the python path
# but this particular project is not a django project. In
# that case, settings aren't configured.
getattr(settings, 'STATSD_HOST', 'localhost')
except ImproperlyConfigured:
settings = None
except ImportError:
settings = None
from .client import StatsClient
from ._version import __version__
__all__ = ['StatsClient', 'statsd']
statsd = None
if settings:
try:
host = getattr(settings, 'STATSD_HOST', 'localhost')
port = getattr(settings, 'STATSD_PORT', 8125)
prefix = getattr(settings, 'STATSD_PREFIX', None)
statsd = StatsClient(host, port, prefix)
except (socket.error, socket.gaierror, ImportError):
pass
elif 'STATSD_HOST' in os.environ:
try:
host = os.environ['STATSD_HOST']
port = int(os.environ['STATSD_PORT'])
prefix = os.environ.get('STATSD_PREFIX')
statsd = StatsClient(host, port, prefix)
except (socket.error, socket.gaierror, KeyError):
pass