python监控rabbitmq的消息队列数量


[root@localhost chen]# cat b.py 
#!/usr/bin/python
# -*- coding: UTF-8 -*-


import json,time
import requests
from requests.auth import HTTPBasicAuth


def check_r(url='http://10.0.0.1:15672',username='xxxxx',password='yyyyyyyy',threshold=100000):
    alert_name = "rabbitmq-%s" % (url,)
    queue_url = 'http://10.1.0.7:15672/api/queues'
    res = requests.get(url=queue_url, auth=HTTPBasicAuth(username='xxxxxx', password='yyyyyyy'))
    if res.status_code == 200:
        queues = json.loads(res.text)
        msg = u"%s rabbitmq消息队列堆积异常:\n" % (time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())),)
        for queue in queues:
            queue_count = int(queue.get("messages", 0))
            if queue_count > threshold:
                print queue
                print queue_count

check_r()

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM