requires a local collectd configured with the unix-sock plugin,
use the --help option for more. Run it with:
$ scyllatop.py --help
Signed-off-by: Yoav Kleinberger <yoav@scylladb.com>
Message-Id: <bd3f8c7e120996fc464f41f60130c82e3fb55ac6.1456164703.git.yoav@scylladb.com>
26 lines
934 B
Python
26 lines
934 B
Python
class Table(object):
|
|
def __init__(self, columns, separator=' '):
|
|
self._columns = columns
|
|
self._separator = separator
|
|
self._rows = []
|
|
self._widths = [0] * len(columns)
|
|
|
|
def add(self, * columns):
|
|
assert len(columns) == len(self._columns), 'wrong number of columns'
|
|
self._rows.append(columns)
|
|
for i, column in enumerate(columns):
|
|
self._widths[i] = max(self._widths[i], len(column))
|
|
|
|
def rows(self):
|
|
for row in self._rows:
|
|
formatted = []
|
|
for i, column in enumerate(row):
|
|
JUSTIFIERS = {'r': column.rjust,
|
|
'l': column.ljust,
|
|
'c': column.center}
|
|
justifier = JUSTIFIERS[self._columns[i]]
|
|
justified = justifier(self._widths[i])
|
|
formatted.append(justified)
|
|
|
|
yield self._separator.join(formatted)
|