solrcloud 监控

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

def monitor(title):
        title_1=str(title)
        print type(title_1)
        cc = pycurl.Curl()
        cc.setopt(cc.URL,'http://alert.sae.sina.com.cn/new/?service=solr_state&checkpoint=solr_state_monitor&title=%s&content=%s&cluster=public&grade=2'%(title_1,title
_1))
        cc.perform()


def work_monitor(ip):
        buf=cStringIO.StringIO()
        c=pycurl.Curl()
        c.setopt(c.URL,'http://%s:8983/solr/zookeeper?wt=json&detail=true&path=%%2Fclusterstate.json'%ip)
        c.setopt(c.WRITEFUNCTION,buf.write)
        c.perform()
        return buf.getvalue()


if __name__ == '__main__':
        ip_list=['10.13.144.224','10.13.144.225','10.13.144.226','10.13.144.227','10.13.144.228','10.13.144.229']
        for i in ip_list:
                a=work_monitor(i)
                json_1=json.loads(a)
                json_2=json.loads(json_1['znode']['data'])
                result=json_2['collection1']['shards']['shard2']['state']
                if result == 'active':
                        monitor(i+'_solrcloud_'+result)
~                                                         

你可能感兴趣的:(监控,title)