#!/usr/bin/python
import json
import pycurl
import cStringIO

def work_url(ip):
        buf=cStringIO.StringIO()
        c=pycurl.Curl()
        c.setopt(c.URL,"http://%s:8983/solr/collection1/admin/mbeans?stats=true&wt=json&_=1409194287592"%ip)
        c.setopt(c.WRITEFUNCTION,buf.write)
        c.perform()
        a=buf.getvalue()
        buf.close()
        return a

if __name__ == '__main__':
        dict={}
        for i in range(4,10):
                ip='10.13.144.22'+str(i)
                b=work_url(ip)
                data=json.loads(b)
                print data
                dict[ip]={}
                select_avgTimePerRequest=data['solr-mbeans'][3]['/select']['stats']['avgTimePerRequest']
                select_avgRequestsPerSecond=data['solr-mbeans'][3]['/select']['stats']['avgRequestsPerSecond']
                cache_document=data['solr-mbeans'][7]['documentCache']['stats']['cumulative_hitratio']
                dict[ip]['select']={}
                dict[ip]['select']['avgTimePerRequest']=select_avgTimePerRequest
                dict[ip]['select']['avgRequestsPerSecond']=select_avgRequestsPerSecond
                dict[ip]['select']['hitratio']=cache_document
        print dict