Files
scylladb/tools/scyllatop/fake.py
Yoav Kleinberger 43071bf488 tools/scyllatop: handle absentee metrics
Sometimes a metric previously reported from collectd is not available
anymore. Previously, this caused scyllatop to log and exception to the
user - which in effect destroyes the user experience and inhibits
monitoring other metrics. This patch makes ScyllaTop handle this
problem. It will display such metrics and 'not available', and exclude
them from some and average computations.

Closes issue #1287.

Signed-off-by: Yoav Kleinberger <yoav@scylladb.com>
Message-Id: <1465301178-27544-1-git-send-email-yoav@scylladb.com>
2016-06-08 16:35:55 +03:00

46 lines
1.2 KiB
Python

import metric
import os
import random
import collectd
import logging
class FakeCollectd(object):
def __init__(self, socketName):
pass
def query(self, command):
pass
Metric = metric.Metric
if 'MARK_ABSENT_PROBABILITY' in os.environ:
MARK_ABSENT_PROBABILITY = float(os.environ['MARK_ABSENT_PROBABILITY'])
else:
MARK_ABSENT_PROBABILITY = 0
class FakeMetric(Metric):
def update(self):
self._status['value'] = random.randint(0, 100000)
if random.random() > 1 - MARK_ABSENT_PROBABILITY:
self.markAbsent()
logging.info('{} {}'.format(self.symbol, self.status))
@classmethod
def discover(self, unused):
results = []
for cpu in range(4):
results += [
FakeMetric('localhost/cpu-{}/cache'.format(cpu), None),
FakeMetric('localhost/cpu-{}/storage_proxy'.format(cpu), None),
FakeMetric('localhost/cpu-{}/transport'.format(cpu), None)]
for x in range(100):
results.append(FakeMetric('localhost/fake_{}/{}'.format(x, random.choice('abcdefghijklmnopqrstuvwxyz')), None))
return results
def fake():
metric.Metric = FakeMetric
collectd.Collectd = FakeCollectd