Skip to content

Instantly share code, notes, and snippets.

Created December 24, 2015 18:30
Show Gist options
  • Save anonymous/58547a2101fcbe1b3704 to your computer and use it in GitHub Desktop.
Save anonymous/58547a2101fcbe1b3704 to your computer and use it in GitHub Desktop.
import requests
import sys
import json
import urllib
import graphitesend
from docopt import docopt
"""
Usage:
sfmetrics.py --sf_host=<sf_host> --sf_user=<sf_user> --sf_password=<sf_password> --graphite_host=<graphite_host> --interval=<interval>
Options:
--sf_host=<sf_host> Solidfire's IP address
--sf_user=<sf_user> Solidfire's username
--sf_host=<sf_password> Solidfire's password
--graphite_host=<graphite_host> Host where graphite is running
--interval=<interval> Time to sleep (in seconds) before polling
"""
class SfApi(object):
def __init__(self, host, user, password):
self.url = "https://%s:%s@%s/json-rpc/8.0" % (user, password, host)
def call(self, method, **kwargs):
q_params = { 'method': method }
q_params.update(kwargs)
res = requests.get(self.url, params=urllib.urlencode(q_params), verify=False)
if not res.ok:
raise AttributeError("Http Error")
json_resp = res.json()
if 'error' in json_resp:
raise AttributeError("SFError: %s:%s" % (json_resp['error']['name'], json_resp['error']['message']))
return json_resp['result']
def generate_graphite_data(sf_metrics):
graphite_data = list()
volume_perf_metrics = ["actualIOPS", "averageIOPSize", "burstIOPSCredit",
"clientQueueDepth", "latencyUSec", "nonZeroBlocks", "readBytes",
"readLatencyUSec", "readOps", "throttle", "unalignedReads",
"unalignedWrites", "volumeSize", "volumeUtilization",
"writeBytes", "writeLatencyUSec", "writeOps" ]
for s in sf_metrics:
vol_name = s['volume_info']['name']
for metric in volume_perf_metrics:
graphite_data.append(('%s.%s' % (vol_name, metric), s[metric]))
return graphite_data
def send_graphite_data(graphite_client, data):
graphite_client.send_list(data)
def get_sf_metrics(client):
volumes = client.call('ListActiveVolumes', startVolumeID=0, limit=1000)['volumes']
stats_data = []
for v in volumes:
stats = client.call('GetVolumeStats', volumeID=v['volumeID'])['volumeStats']
stats['volume_info'] = v
stats_data.append(stats)
return stats_data
def main(sf_host, sf_user, sf_password, graphite_host, interval_sec):
while True:
sf_client = SfApi(sf_host, sf_user, sf_password)
graphite_client = graphitesend.init(prefix='solidfire', graphite_server=graphite_server)
sf_metrics = get_sf_metrics(sf_client)
graphite_data = generate_graphite_data(sf_metrics)
send_graphite_data(graphite_client, graphite_data)
sleep(interval_sec)
if __name__ == "__main__":
print __doc__
args = docopt(__doc__)
main(args['--sf_host'],
args['--sf_user'],
args['--sf_password'],
args['--graphite_host'],
args['--interval']
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment