Skip to content

Instantly share code, notes, and snippets.

@wkalt
Created April 29, 2016 22:52
Show Gist options
  • Save wkalt/e0bf0621f6f55060039075773fb5a3f4 to your computer and use it in GitHub Desktop.
Save wkalt/e0bf0621f6f55060039075773fb5a3f4 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import urllib2
import time
url = "http://localhost:8080/metrics/v1/mbeans/java.lang:type=Memory"
outputfile = "/var/log/puppetlabs/puppetdb/heap-usage.log"
if __name__ == '__main__':
try:
heap_data = json.load(urllib2.urlopen(url))['HeapMemoryUsage']
out = open(outputfile, 'a')
line = ",".join([str(time.time()),
str(heap_data['committed']),
str(heap_data['used'])]) + '\n'
out.write(line)
out.close()
except:
None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment