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 90ba362..125194b 100755 --- a/stormkafkamon/monitor.py +++ b/stormkafkamon/monitor.py @@ -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), + fmt(p.delta)]) print table.get_string(sortby='Broker') print print 'Number of brokers: %d' % summary.num_brokers @@ -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() @@ -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