Created
October 2, 2014 19:04
-
-
Save tdhopper/7bce9652c16ba0a34fcb to your computer and use it in GitHub Desktop.
Hacky way to get a table showing uptime for all Storm workers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import requests | |
| username = 'STORM-UI-USERNAME' | |
| password = 'STORM-UI-PASSWORD' | |
| base_url = 'STORM-UI-URL' | |
| cluster_summary = '/api/v1/cluster/summary' | |
| topology_summary = '/api/v1/topology/summary' | |
| topology_detail = '/api/v1/topology/{topology}' | |
| component = '/api/v1/topology/{topology}/component/{component}' | |
| def get_data(base, endpoint, username, password): | |
| return requests.request("GET", base + endpoint, auth=(username, password)).json() | |
| if __name__ == '__main__': | |
| topology_ids = map(lambda x: x['id'], get_data(base_url, topology_summary, username, password)['topologies']) | |
| worker_stats = [] | |
| for topology in topology_ids: | |
| topology_detail_json = get_data(base_url, topology_detail.format(topology=topology), username, password) | |
| spouts = map(lambda x: x['spoutId'], topology_detail_json['spouts']) | |
| bolts = map(lambda x: x['boltId'], topology_detail_json['bolts']) | |
| for comp in spouts + bolts: | |
| comp_detail = get_data(base_url, component.format(topology=topology, component = comp), username, password) | |
| worker_stats += [(worker['host'], worker['id'], worker['uptime']) for worker in comp_detail['executorStats']] | |
| print pd.DataFrame(sorted(list(set(worker_stats)))).to_string(header=False, index=False) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
output looks like this: