From cc47d8fc8e34ac375f0b9aca82e8a36470d94eac Mon Sep 17 00:00:00 2001 From: Shin Tokiwa Date: Tue, 27 Aug 2013 23:33:17 +0900 Subject: [PATCH 1/2] Fix display bug and improve numeric format * Replace the caption from lowercase to uppercase * Each column of numeric type uses right-align * Apply comma format to some numerical columns in case of friendly mode --- stormkafkamon/monitor.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/stormkafkamon/monitor.py b/stormkafkamon/monitor.py index 90ba362..28cdcc9 100755 --- a/stormkafkamon/monitor.py +++ b/stormkafkamon/monitor.py @@ -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), + fmt(p.delta)]) print table.get_string(sortby='Broker') print print 'Number of brokers: %d' % summary.num_brokers From 6462d6c66f34e5a40ec11f55f1e4581fb346efb5 Mon Sep 17 00:00:00 2001 From: Shin Tokiwa Date: Wed, 11 Sep 2013 17:37:32 +0900 Subject: [PATCH 2/2] Support commify option --- example | 61 ++++++++++++++++++++++++++++++++++++++++ stormkafkamon/monitor.py | 16 +++++++---- 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/example b/example index 1dedb6f..f6aa1e7 100644 --- a/example +++ b/example @@ -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 + diff --git a/stormkafkamon/monitor.py b/stormkafkamon/monitor.py index 28cdcc9..125194b 100755 --- a/stormkafkamon/monitor.py +++ b/stormkafkamon/monitor.py @@ -22,14 +22,17 @@ def null_fmt(num): def comma_fmt(num): return "{:,d}".format(num) -def display(summary, friendly=False): - if friendly: - fmt = sizeof_fmt +def display(summary, friendly=False, commify=False): + if commify: cfmt = comma_fmt else: - fmt = null_fmt cfmt = null_fmt + if friendly: + fmt = sizeof_fmt + else: + fmt = cfmt if commify else null_fmt + table = PrettyTable(['Broker', 'Topic', 'Partition', 'Earliest', 'Latest', 'Depth', 'Spout', 'Current', 'Delta']) table.align['Broker'] = 'l' @@ -86,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() @@ -107,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