码迷,mamicode.com
首页 > 其他好文 > 详细

123123

时间:2017-12-26 14:27:18      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:cos   evel   cee   时间   str   turn   for   nlog   rtb   

# encoding=UTF-8

import logging
import sys
sys.path.append(".")
import Collector
import logging
import logging.handlers
import datetime
import os
import json

class emailMonitor_Mtrs(Collector.Collector):
    collect_datas = []
    _app_list = []

    def __init__(self):
        self.setMetricsKey("emailMonitor")
        self.__init_collect_datas()

    def __init_collect_datas(self):
        self.collect_datas = [
            {
                ‘showDetails‘: ‘false‘,
                ‘emailSendTimeCostAvg‘: 0,
                ‘emailSendTimeCostMax‘: 6000,
                ‘emailServerApiTimeCostAvg‘: 3000,
                ‘emailSendSucceedCount‘: 0,
                ‘emailSendFailedCount‘: 0,
                ‘unavailableServerNumber‘: 0,
                ‘tenantId‘: ‘‘
            }
        ]

    def collect(self, process_filter):
        self.execute("curl -k http://sgbeta.owsgo.com:%s/heartbeat.jsp?monitorNames=emailMonitor" % self.app)

        try:
            result_json_str = self.parse(r‘\s*(\{[\s\S]*\})\s*‘)
            result_dict = json.loads(result_json_str)
            emailMonitorResultCode = int(result_dict[‘monitorResultMap‘][‘emailMonitor‘][‘resultCode‘])
        except Exception, ex:
            logging.exception(ex)
        try:
            detailResult = result_dict[‘monitorResultMap‘][‘emailMonitor‘][‘detailResult‘]
            emailSendTimeCostMax = int(detailResult[‘emailSendTimeCostMax‘])
        except Exception, ex:
            logging.exception(ex)
        try:
            timeCostToWriteESMax = int(detailResult[‘timeCostToWriteESMax‘])
        except Exception, ex:
            logging.exception(ex)

        locals_dict = locals()
        for each_data in self.collect_datas:
            name = each_data["name"]
            if locals_dict.has_key(name):
                each_data["total_value"] += locals_dict[name]
                each_data["total_count"] += 1
            else:
                each_data["total_value"] += each_data["exception_value"]
                each_data["total_count"] += 1


if __name__ == "__main__":
    monitor = emailMonitor_Mtrs()
    monitor.collect("")

    print monitor.collect_datas
# encoding=UTF-8
#name:liveQueryMonitor_Mtrs.py

import sys
import json
import logging

sys.path.append(".")
import Collector


class LiveQueryMonitor_Mtrs(Collector.Collector):
    
    def __init__(self):
        self.setMetricsKey("LiveQueryMonitor")
        self.__init_collect_datas()
        
    #指令执行的超时时间,默认为15秒
    def getTimeout(self):
        return 30
        
    def __init_collect_datas(self):
        self.collect_datas = [
            {
                ‘unit‘: ‘Count‘,
                ‘total_value‘: 0,
                ‘total_count‘: 0,
                ‘exception_value‘: 10000,
                ‘divide_value‘: 1,
                ‘name‘: ‘topicMessageReceiveDelayMax‘
            },{
                ‘unit‘: ‘Count‘,
                ‘total_value‘: 0,
                ‘total_count‘: 0,
                ‘exception_value‘: 10000,
                ‘divide_value‘: 1,
                ‘name‘: ‘liveDataPushDelayMax‘
            }
        ]
        
    # 指令执行的超时时间
    def getTimeout(self):
        return 20
        
    def collect(self, process_filter):

        # LiveQueryMonitor
        try:
            self.execute("curl -k http://127.0.0.1:%s/livequery/heartbeat.jsp?monitorNames=LiveQueryMonitor" % self.tomcat_port)
            result_json_str = self.parse(r‘\s*(\{[\s\S]*\})\s*‘)
            result_dict = json.loads(result_json_str)
        except Exception, ex:
            logging.exception(ex)

        # 从binlogreader发送Topic消息到消息接收延迟(liveTable收到jms相对发的时延) 
        try: 
            LiveQueryDetailResult = result_dict[‘monitorResultMap‘][‘LiveQueryMonitor‘][‘detailResult‘]
            topicMessageReceiveDelayMax = int(LiveQueryDetailResult[‘topicMessageReceiveDelayMax‘])
        except Exception, ex:
            logging.exception(ex)
            
        # JMS消息收到到准备推送的延迟(向前台推送的相对收到jms的时延)
        try: 
            liveDataPushDelayMax = int(LiveQueryDetailResult[‘liveDataPushDelayMax‘])
        except Exception, ex:
            logging.exception(ex)
            
            
        locals_dict = locals()
        for each_data in self.collect_datas:
            name = each_data["name"]
            if locals_dict.has_key(name):
                each_data["total_value"] += locals_dict[name]
                each_data["total_count"] += 1
            else:
                each_data["total_value"] += each_data["exception_value"]
                each_data["total_count"] += 1
            
            
            
                     
if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    monitor = CanalMonitor_Mtrs()    
    monitor.collect("")
    print monitor.collect_datas
    
     
     
            
        

 

123123

标签:cos   evel   cee   时间   str   turn   for   nlog   rtb   

原文地址:https://www.cnblogs.com/storm1018/p/8117370.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!