Skip to content

Commit

Permalink
Calculate the used space for a datastore in percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Jun 28, 2013
1 parent 9b0dc41 commit 6f82fe8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions poller/vm-poller.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,12 @@ def poll_datastores(self):
d[property_macros[p.Name]] = timestamp
else:
d[property_macros[p.Name]] = p.Val


# calculate the used space in percentage
d['{#DS_USED_SPACE}'] = round(100 - ((float(d['{#DS_FREESPACE}']) / float(d['{#DS_CAPACITY}']) * 100)), 2)

json_data.append(d)

print json.dumps({ 'data': json_data}, indent=4)

def parse_config(conf):
Expand All @@ -189,13 +192,13 @@ def parse_config(conf):
def main():

if len(sys.argv) != 4:
print 'usage: %s -f config' % sys.argv[0]
print 'usage: %s [-D|-H] -f config' % sys.argv[0]
raise SystemExit

try:
opts, args = getopt.getopt(sys.argv[1:], "f:DH")
except getopt.GetoptError, e:
print 'usage: %s -f config' % sys.argv[0]
print 'usage: %s [-D|-H] -f config' % sys.argv[0]
raise SystemExit

for opt, arg in opts:
Expand Down

0 comments on commit 6f82fe8

Please sign in to comment.