Skip to content

Instantly share code, notes, and snippets.

@gowatana
Last active October 7, 2017 14:56
Show Gist options
  • Save gowatana/0e3e6f20d700877b6cb9beb8c9e4309c to your computer and use it in GitHub Desktop.
Save gowatana/0e3e6f20d700877b6cb9beb8c9e4309c to your computer and use it in GitHub Desktop.
import sys
import json
import requests
import datetime
args = sys.argv
conf_file = args[1]
metrics_file_name = args[2]
with open(conf_file, "r") as file:
conf = file.read()
conf = json.loads(conf)
prism_addr = conf["prism_address"]
prism_user = conf["user_name"]
prism_pass = conf["password"]
def get_metrics_str(metrics_file_name):
with open(metrics_file_name, "r") as file:
metrics = file.read()
metrics = metrics.split()
metrics_str = "%2C".join(metrics)
return metrics_str
def main():
base_url = 'https://' + prism_addr + ':9440/PrismGateway/services/rest/v2.0'
requests.packages.urllib3.disable_warnings()
s = requests.Session()
s.auth = (prism_user, prism_pass)
s.headers.update({'Content-Type': 'application/json; charset=utf-8'})
metrics_str = get_metrics_str(metrics_file_name)
api_url = base_url + '/hosts'
hosts = s.get(api_url, verify=False).json()
for host in hosts['entities']:
host_name = host['name']
host_uuid = host['uuid']
api_url = base_url + '/hosts/' + host_uuid + '/stats/?metrics=' + metrics_str
stats = s.get(api_url, verify=False).json()
for stat in stats['stats_specific_responses']:
stat_metric = stat['metric']
stat_timestamp = datetime.datetime.fromtimestamp(int(stat['start_time_in_usecs']) / 1000000)
stat_value = stat['values'][0]
print '{0},\t{1},\t{2},\t{3}'.format(host_name, stat_timestamp, stat_metric, stat_value)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment