Skip to content

Instantly share code, notes, and snippets.

@rsff
Created March 18, 2015 12:23
Show Gist options
  • Save rsff/067cfdad9e1e858da863 to your computer and use it in GitHub Desktop.
Save rsff/067cfdad9e1e858da863 to your computer and use it in GitHub Desktop.
jolokia to d3 extractor
#!/usr/bin/python
'''
get jolokia data and write a csv in a folder so it can be
processed by the d3
'''
from pyjolokia import Jolokia
__author__ = "Ricardo Ferreira"
__status__ = "Prototype"
servu = 'http://server:8004/jolokia/'
def get_all_metrics(server):
rawdata = []
j4p = Jolokia(server)
metrics = j4p.request(type='search', mbean='metrics:*')
for x in metrics['value']:
rawdata.append(j4p.request(type='read', mbean=x))
return rawdata
def create_dicto_mean(data):
mean = {}
for x in data:
mean[x['request']['mbean'].split('=')[1]] = x['value']['Mean']
return mean
def create_dicto_count(data):
count = {}
for x in data:
count[x['request']['mbean'].split('=')[1]] = x['value']['Count']
return count
def return_csv(mean, count):
lista = []
for k, v in mean.items():
for a, b in count.items():
if k == a and b > 10:
tmplist = [k, v, b]
lista.append(tmplist)
return lista
def write_csv(lista):
file = open('/opt/d3/test.csv', 'w')
file.write('Name,Mean,Count\n')
size = len(lista)
for i in range(size):
file.write(', '.join(map(str, lista[i])) + '\n')
file.close()
def main():
metrics = get_all_metrics(servu)
mean = create_dicto_mean(metrics)
count = create_dicto_count(metrics)
write_csv(return_csv(mean, count))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment