Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Fix display bug and improve numeric format #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions stormkafkamon/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,30 @@ def sizeof_fmt(num):
def null_fmt(num):
return num

def comma_fmt(num):
return "{:,d}".format(num)

def display(summary, friendly=False):
if friendly:
fmt = sizeof_fmt
cfmt = comma_fmt
else:
fmt = null_fmt
cfmt = null_fmt

table = PrettyTable(['Broker', 'Topic', 'Partition', 'Earliest', 'Latest',
'Depth', 'Spout', 'Current', 'Delta'])
table.align['broker'] = 'l'
table.align['Broker'] = 'l'
table.align['Earliest'] = 'r'
table.align['Latest'] = 'r'
table.align['Depth'] = 'r'
table.align['Current'] = 'r'
table.align['Delta'] = 'r'

for p in summary.partitions:
table.add_row([p.broker, p.topic, p.partition, p.earliest, p.latest,
fmt(p.depth), p.spout, p.current, fmt(p.delta)])
table.add_row([p.broker, p.topic, p.partition, cfmt(p.earliest),
cfmt(p.latest), fmt(p.depth), p.spout, cfmt(p.current),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer not to have commas by default. Perhaps it could be switch?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okey, I'll try to add 'commify' option newly.

fmt(p.delta)])
print table.get_string(sortby='Broker')
print
print 'Number of brokers: %d' % summary.num_brokers
Expand Down