示例#1
0
def run():
    monitor = Monitor()
    while True:
        try:
            monitor.check()
        except Exception, e:
            log.error(e)
        time.sleep(ConfUtil.getCycle())
def run():
    monitor = Monitor()
    while True:
        try:
            monitor.check()
        except Exception, e:
            log.error(e)
        time.sleep(ConfUtil.getCycle())
示例#3
0
def index():
    try:
        addrList = ConfUtil.getMQAddrList()
        addr = request.args.get('addr', addrList[0])
        queues = MQService.getQueues(addr)
        addrList.remove(addr)
        addrList.insert(0, addr)
    except Exception, e:
        log.error(e)
def index():
    try:
        addrList = ConfUtil.getMQAddrList()
        addr = request.args.get('addr', addrList[0])
        queues = MQService.getQueues(addr)
        addrList.remove(addr)
        addrList.insert(0, addr)
    except Exception, e:
        log.error(e)
示例#5
0
def getQueues(addr):
    queueUrl = 'http://' + addr.strip() + '/api/queues'
    res = requests.get(queueUrl, auth=(ConfUtil.getMQUsername(), ConfUtil.getMQPassword()))
    queues = []
    index = 0
    for queue in json.loads(res.text):
        queueName = queue.get('name')
        msgTotal = queue.get('messages', 0)
        dict = {}
        dict['queue'] = queueName
        dict['msgTotal'] = msgTotal
        index += 1
        dict['index'] = index
        doc = MonitorDao.findQueue(addr, queueName)
        dict['mailList'] = ''
        dict['msgTotalMax'] = ''
        if doc != None:
            dict['mailList'] = ','.join(doc.get('mailList'))
            dict['msgTotalMax'] = doc.get('msgTotalMax')
        queues.append(dict)
    return queues
示例#6
0
 def check(self):
     mailContent = {}
     for mail in ConfUtil.getGlobalMailList():
         mailContent[mail.strip()] = [] 
     for addr in self.__addrList:
         overviewUrl = 'http://' + addr.strip() + '/api/overview'
         try:
             res = requests.get(overviewUrl, auth=(self.__username, self.__password))
         except ConnectionError, e:
             for mail in ConfUtil.getGlobalMailList():
                 mailContent[mail].append(addr + ' is dead.')
             continue
         queueUrl = 'http://' + addr.strip() + '/api/queues'
         res = requests.get(queueUrl, auth=(self.__username, self.__password))
         for queue in json.loads(res.text):
             queueName = queue.get('name')
             if queueName in ConfUtil.getIgnoreQueueList():
                 continue
             messages = queue.get('messages', 0)
             doc = MonitorDao.findQueue(addr, queueName)
             if doc == None:
                 if messages > ConfUtil.getGlobalMsgTotalMax():
                     alarm = addr + ', ' + queueName + ', ' + 'msgTotal is ' + str(messages) + '(' + str(ConfUtil.getGlobalMsgTotalMax()) + ').'    
                     for mail in ConfUtil.getGlobalMailList():
                         mailContent[mail].append(alarm)
             else:
                 try:
                     msgTotalMax = 0
                     if len(doc.get('msgTotalMax')) > 0:
                         msgTotalMax = (int)(doc.get('msgTotalMax'))
                 except Exception, e:
                     log.error(doc)
                 mailList = doc.get('mailList')
                 if messages > msgTotalMax:
                     alarm = addr + ', ' + queueName + ', ' + 'msgTotal is ' + str(messages) + '(' + str(msgTotalMax) + ').'
                     for mail in mailList:
                         if mailContent.get(mail) == None:
                             mailContent[mail] = []
                         mailContent[mail.strip()].append(alarm)
示例#7
0
 def check(self):
     mailContent = {}
     for mail in ConfUtil.getGlobalMailList():
         mailContent[mail.strip()] = []
     for addr in self.__addrList:
         overviewUrl = 'http://' + addr.strip() + '/api/overview'
         try:
             res = requests.get(overviewUrl,
                                auth=(self.__username, self.__password))
         except ConnectionError, e:
             for mail in ConfUtil.getGlobalMailList():
                 mailContent[mail].append(addr + ' is dead.')
             continue
         queueUrl = 'http://' + addr.strip() + '/api/queues'
         res = requests.get(queueUrl,
                            auth=(self.__username, self.__password))
         for queue in json.loads(res.text):
             queueName = queue.get('name')
             if queueName in ConfUtil.getIgnoreQueueList():
                 continue
             messages = queue.get('messages', 0)
             doc = MonitorDao.findQueue(addr, queueName)
             if doc == None:
                 if messages > ConfUtil.getGlobalMsgTotalMax():
                     alarm = addr + ', ' + queueName + ', ' + 'msgTotal is ' + str(
                         messages) + '(' + str(
                             ConfUtil.getGlobalMsgTotalMax()) + ').'
                     for mail in ConfUtil.getGlobalMailList():
                         mailContent[mail].append(alarm)
             else:
                 try:
                     msgTotalMax = 0
                     if len(doc.get('msgTotalMax')) > 0:
                         msgTotalMax = (int)(doc.get('msgTotalMax'))
                 except Exception, e:
                     log.error(doc)
                 mailList = doc.get('mailList')
                 if messages > msgTotalMax:
                     alarm = addr + ', ' + queueName + ', ' + 'msgTotal is ' + str(
                         messages) + '(' + str(msgTotalMax) + ').'
                     for mail in mailList:
                         if mailContent.get(mail) == None:
                             mailContent[mail] = []
                         mailContent[mail.strip()].append(alarm)
示例#8
0
 def __init__(self):
     self.__addrList = ConfUtil.getMQAddrList()
     self.__username = ConfUtil.getMQUsername()
     self.__password = ConfUtil.getMQPassword()
示例#9
0
 def __init__(self):
     self.__addrList = ConfUtil.getMQAddrList()
     self.__username = ConfUtil.getMQUsername()
     self.__password = ConfUtil.getMQPassword()
示例#10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on Sep 27, 2015

@author: mountain
'''
from app.util import ConfUtil
import smtplib
import requests
from email.mime.text import MIMEText
from email.header import Header
from app.util.LogUtil import log

fromAddr = ConfUtil.getFromAddr()
smtpServer = ConfUtil.getSmtpServer()
smtpPort = ConfUtil.getSmtpPort()
password = ConfUtil.getMailPassword()
url = ConfUtil.getPostUrl()

def sendMail(toAddr, content):
    server = smtplib.SMTP(smtpServer, smtpPort)
    server.set_debuglevel(1)
    server.login(fromAddr, password)
    message = MIMEText(content, 'plain', 'utf-8')
    message['Subject'] = Header(u'RabbitMQ报警', 'utf-8').encode()
    server.sendmail(fromAddr, toAddr, message.as_string())
    server.quit()

def sendMultiMail(data):
    print data
示例#11
0
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on Sep 24, 2015

@author: mountain
'''
from pymongo import MongoClient
from app.util import ConfUtil

client = MongoClient(ConfUtil.getMongoHost(), ConfUtil.getMongoPort())
db = client.mq_monitor
queue = db.queue
user = db.user

def saveQueue(data):
    queue.update({'queue': data.get('queue')}, data, upsert=True)

def findQueue(addr, queueName):
    return queue.find_one({'queue': queueName, 'addr': addr})
    
if __name__ == '__main__':
    print findQueue('c') == None
示例#12
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on Sep 27, 2015

@author: mountain
'''
from app.util import ConfUtil
import smtplib
import requests
from email.mime.text import MIMEText
from email.header import Header
from app.util.LogUtil import log

fromAddr = ConfUtil.getFromAddr()
smtpServer = ConfUtil.getSmtpServer()
smtpPort = ConfUtil.getSmtpPort()
password = ConfUtil.getMailPassword()


def sendMail(toAddr, content):
    server = smtplib.SMTP(smtpServer, smtpPort)
    server.set_debuglevel(1)
    server.login(fromAddr, password)
    message = MIMEText(content, 'plain', 'utf-8')
    message['Subject'] = Header(u'RabbitMQ报警', 'utf-8').encode()
    server.sendmail(fromAddr, toAddr, message.as_string())
    server.quit()


def sendMultiMail(data):