def __init__(self, topics):
        self.fqdn = socket.getfqdn()
        self.pc = pystatsd.Client(prefix=self.fqdn)

        self.statistics_subs = []
        for topic in topics:
            statistics_sub = rospy.Subscriber(topic['name'], Statistics, self.statistics_callback, \
                                              callback_args=topic['stats'])
            self.statistics_subs.append(statistics_sub)
Example #2
0
 def __init__(self, settings):
     try:
         import pystatsd
     except ImportError as ie:
         raise ImportError(
             'Metrics collection is enabled, but we failed to '
             'import "pystatsd": {0}'.format(unicode(ie)))
     prefix = getattr(settings, 'METRICS_PREFIX', None)
     host = getattr(settings, 'METRICS_HOST', DEFAULT_STATSD_HOST)
     port = getattr(settings, 'METRICS_PORT', DEFAULT_STATSD_PORT)
     self._client = pystatsd.Client(host, port, prefix=prefix)
Example #3
0
def log_timing(key, timing, server=None, port=None, request=None):
    if not server or not port:
        if not request:
            request = threadlocal.get_current_request()
        registry = request.registry
        settings = registry.settings
        if not server:
            server = settings.get('epfl.performance_log.server')
        if not port:
            port = int(settings.get('epfl.performance_log.port'))

    if use_statsd:
        client = statsd.StatsClient(server, port)
    else:
        client = pystatsd.Client(server, port)

    client.timing(key, timing)
Example #4
0
 def __init__(self):
     self.config = yaml.load(open(os.path.join(ROOT, 'config.yaml')))
     self.stats = pystatsd.Client(self.config['host'])
     self.stats.prefix = self.config['prefix']
     self.db = yaml.load(open(os.path.join(ROOT, 'db.yaml'))) or {}
import subprocess
import os
import pystatsd
import time

stats_client = pystatsd.Client(os.environ.get('STATSD_HOST', '127.0.0.1'),
                               8125)

# This is not ideal, but whatever. Originally I had this at 0.5 sec interval, but it wasnt worth it
# and my Netgear router was whining about ICMP floods.
process = subprocess.Popen(["ping", '-i', '1.0', '8.8.8.8'],
                           stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT)

seen_seq = 1
loop_iter = 0
for line in iter(process.stdout.readline, ''):
    if 'bytes from' in line:
        loop_iter += 1

        chunks = line.rstrip().split()
        print line.rstrip()
        latency = int(float(chunks[-2].split('=')[-1]))
        # ping2 because the first version of this script was JANK
        stats_client.gauge('ping2.latency.8_8_8_8', latency)
        stats_client.timing('ping2.latency.8_8_8_8', latency)

        seen_seq = int(chunks[4].split('=')[-1])

        # if you have ever ran `ping 8.8.8.8` on Linux, you know it prints
        # one log line per received packet. if you miss a ton, you just dont get any
Example #6
0
from m3.actions import ControllerCache

try:
    import pystatsd
except ImportError as ie:
    raise ImportError('Metrics collection is enabled, but we failed to '
                      'import "pystatsd": {0}'.format(unicode(ie)))

prefix = getattr(settings, 'METRICS_PREFIX', None)
host = getattr(settings, 'METRICS_HOST', 'localhost')
port = getattr(settings, 'METRICS_PORT', 8125)
endpoint_url = getattr(settings, 'METRICS_CONTEXTS_URL',
                       'http://localhost:1942/register')

statsd_client = pystatsd.Client(host, port, prefix=prefix)


def gauge_user_count():
    statsd_client.gauge('users.count', User.objects.count())


def gauge_active_users():
    statsd_client.gauge('users.active', Session.objects.count())


def logged_out(**kwargs):
    statsd_client.decr('users.active')


def logged_in(**kwargs):