Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.
Merged
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
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'kazoo==1.00',
'simplejson',
'argparse',
'requests',
'kafka-python'
]

Expand Down
27 changes: 25 additions & 2 deletions stormkafkamon/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import argparse
import sys
from prettytable import PrettyTable
import requests
import simplejson as json

from zkclient import ZkClient, ZkError
from processor import process, ProcessorError
Expand Down Expand Up @@ -37,6 +39,21 @@ def display(summary, friendly=False):
print 'Total broker depth: %s' % fmt(summary.total_depth)
print 'Total delta: %s' % fmt(summary.total_delta)

def post_json(endpoint, zk_data):
fields = ("broker", "topic", "partition", "earliest", "latest", "depth",
"spout", "current", "delta")
json_data = {"%s-%s" % (p.broker, p.partition):
{name: getattr(p, name) for name in fields}
for p in zk_data.partitions}
total_fields = ('depth', 'delta')
total = {fieldname:
sum(getattr(p, fieldname) for p in zk_data.partitions)
for fieldname in total_fields}
total['partitions'] = len({p.partition for p in zk_data.partitions})
total['brokers'] = len({p.broker for p in zk_data.partitions})
json_data['total'] = total
requests.post(endpoint, data=json.dumps(json_data))

######################################################################

def true_or_false_option(option):
Expand All @@ -58,6 +75,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('--postjson', type=str,
help='endpoint to post json data to')
return parser.parse_args()

def main():
Expand All @@ -66,14 +85,18 @@ def main():
zc = ZkClient(options.zserver, options.zport)

try:
display(process(zc.spouts(options.spoutroot, options.topology)),
true_or_false_option(options.friendly))
zk_data = process(zc.spouts(options.spoutroot, options.topology))
Copy link
Contributor

Choose a reason for hiding this comment

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

Move into an else clause?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, the stuff after this call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, done.

On Mon, Aug 5, 2013 at 2:28 PM, philip-loggly notifications@github.comwrote:

In stormkafkamon/monitor.py:

@@ -66,8 +85,11 @@ def main():
zc = ZkClient(options.zserver, options.zport)

 try:
  •    display(process(zc.spouts(options.spoutroot, options.topology)),
    
  •            true_or_false_option(options.friendly))
    
  •    zk_data = process(zc.spouts(options.spoutroot, options.topology))
    

I mean, the stuff after this call.


Reply to this email directly or view it on GitHubhttps://github.com//pull/3/files#r5590742
.

except ZkError, e:
print 'Failed to access Zookeeper: %s' % str(e)
return 1
except ProcessorError, e:
print 'Failed to process: %s' % str(e)
return 1
else:
if options.postjson:
post_json(options.postjson, zk_data)
else:
display(zk_data, true_or_false_option(options.friendly))

return 0

Expand Down