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
Show file tree
Hide file tree
Changes from all commits
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
61 changes: 61 additions & 0 deletions example
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,64 @@ Number of brokers: 2
Number of partitions: 8
Total broker depth: 89.9GB
Total delta: 1.8MB


##### No format option #####
skmon --zserver zookeeper0 --topology FooTopology --spoutroot /consumers
+--------+-------+-----------+-----------+-----------+-----------+------------+-----------+-------+
| Broker | Topic | Partition | Earliest | Latest | Depth | Spout | Current | Delta |
+--------+-------+-----------+-----------+-----------+-----------+------------+-----------+-------+
| kafka0 | hoge | 0 | 536871088 | 614696053 | 77824965 | bar_spout | 614659926 | 36127 |
| kafka1 | hoge | 0 | 0 | 421117523 | 421117523 | bar_spout | 421103798 | 13725 |
+--------+-------+-----------+-----------+-----------+-----------+------------+-----------+-------+

Number of brokers: 2
Number of partitions: 2
Total broker depth: 498942488
Total delta: 49852


##### With friendly option #####
skmon --zserver zookeeper0 --topology FooTopology --spoutroot /consumers --friendly
+--------+-------+-----------+-----------+-----------+---------+-----------+-----------+--------+
| Broker | Topic | Partition | Earliest | Latest | Depth | Spout | Current | Delta |
+--------+-------+-----------+-----------+-----------+---------+-----------+-----------+--------+
| kafka0 | hoge | 0 | 536871088 | 614696053 | 74.2MB | bar_spout | 614659926 | 35.3KB |
| kafka1 | hoge | 0 | 0 | 421117523 | 401.6MB | bar_spout | 421103798 | 13.4KB |
+--------+-------+-----------+-----------+-----------+--------+------------+-----------+--------+

Number of brokers: 2
Number of partitions: 2
Total broker depth: 475.8MB
Total delta: 48.7KB


##### With commify option #####
skmon --zserver zookeeper0 --topology FooTopology --spoutroot /consumers --commify
+--------+-------+-----------+-------------+-------------+-------------+-----------+-------------+--------+
| Broker | Topic | Partition | Earliest | Latest | Depth | Spout | Current | Delta |
+--------+-------+-----------+-------------+-------------+-------------+-----------+-------------+--------+
| kafka0 | hoge | 0 | 536,871,088 | 614,696,053 | 77,824,965 | bar_spout | 614,659,926 | 36,127 |
| kafka1 | hoge | 0 | 0 | 421,117,523 | 421,117,523 | bar_spout | 421,103,798 | 13,725 |
+--------+-------+-----------+-------------+-------------+-------------+-----------+-------------+--------+

Number of brokers: 2
Number of partitions: 2
Total broker depth: 498,942,488
Total delta: 49,852


##### With friendly and commify options #####
skmon --zserver zookeeper0 --topology FooTopology --spoutroot /consumers --friendly --commify
+--------+-------+-----------+-------------+-------------+---------+-----------+-------------+--------+
| Broker | Topic | Partition | Earliest | Latest | Depth | Spout | Current | Delta |
+--------+-------+-----------+-------------+-------------+---------+-----------+-------------+--------+
| kafka0 | hoge | 0 | 536,871,088 | 614,696,053 | 74.2MB | bar_spout | 614,659,926 | 35.3KB |
| kafka1 | hoge | 0 | 0 | 421,117,523 | 401.6MB | bar_spout | 421,103,798 | 13.4KB |
+--------+-------+-----------+-------------+-------------+---------+-----------+-------------+--------+

Number of brokers: 2
Number of partitions: 2
Total broker depth: 475.8MB
Total delta: 48.7KB

29 changes: 23 additions & 6 deletions stormkafkamon/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,33 @@ def sizeof_fmt(num):
def null_fmt(num):
return num

def display(summary, friendly=False):
def comma_fmt(num):
return "{:,d}".format(num)

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

if friendly:
fmt = sizeof_fmt
else:
fmt = null_fmt
fmt = cfmt if commify else 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 Expand Up @@ -75,6 +89,8 @@ def read_args():
help='Root path for Kafka Spout data in Zookeeper')
parser.add_argument('--friendly', action='store_const', const=True,
help='Show friendlier data')
parser.add_argument('--commify', action='store_const', const=True,
help='Comma format')
parser.add_argument('--postjson', type=str,
help='endpoint to post json data to')
return parser.parse_args()
Expand All @@ -96,7 +112,8 @@ def main():
if options.postjson:
post_json(options.postjson, zk_data)
else:
display(zk_data, true_or_false_option(options.friendly))
display(zk_data, true_or_false_option(options.friendly),
true_or_false_option(options.commify))

return 0

Expand Down