Example #1
0
 def run(self):
     while True:
         try:
             import gevent
             gevent.sleep(10)
         except:
             break
     stop_pinpoint_agent()
     TCLogger.warning("collector agent exit with SIGNAL")
Example #2
0
 def start(self):
     self.__socket = asy_socket.socket(asy_socket.AF_INET,
                                       asy_socket.SOCK_DGRAM)
     self.__socket.setblocking(False)
     try:
         self.state = E_CONNECTED
         self.__socket.connect(self.remote)
     except asy_socket.error as e:
         if not (e.errno in (errno.EINPROGRESS, errno.EWOULDBLOCK)):
             TCLogger.warning("connect:%s error:%s" % (self.remote, str(e)))
             self.__socket.close()
             raise Exception("create DgramLayer failed")
Example #3
0
    def __init__(self, agentId, startTimeStamp, host):
        self.state = TAgentStat()
        self.cup_load = TCpuLoad()
        self.state.agentId = agentId
        self.state.startTimestamp = startTimeStamp
        self.stateBatch = TAgentStatBatch()
        self.stateBatch.agentId = agentId
        self.stateBatch.startTimestamp = startTimeStamp
        self.stateBatch.agentStats = []
        self.remote = host

        self.trans_layer = DgramLayer(host, None)
        self.trans_layer.start()

        TrainLayer.registerTimers(self.sendState, 20)
        TCLogger.debug("register state timer")
Example #4
0
 def sendState(self, layer):
     self._upDateCurState()
     body = CollectorPro.obj2bin(self.stateBatch, AGENT_STAT_BATCH)
     TCLogger.debug("send state:%s", self.stateBatch)
     self.trans_layer.sendData(body)
    def genTspan(self, span, interceptManger):
        '''

        :param dict span:
        :param InterceptManager interceptManger
        :return :
        '''

        tSpan = TSpan()
        tSpan.apiId = interceptManger.updateApiMeta(span['name'],
                                                    API_WEB_REQUEST).apiId
        tSpan.spanId = CollectorPro.createSpanid()
        tSpan.applicationName = interceptManger.ac.ApplicationName
        tSpan.agentStartTime = interceptManger.startTimeStamp
        tSpan.agentId = interceptManger.ac.AgentID

        if 'stp' in span:
            tSpan.serviceType = int(span['stp'])
            tSpan.applicationServiceType = int(span['stp'])
        else:
            tSpan.serviceType = PHP
            tSpan.applicationServiceType = PHP

        if 'psid' in span:
            tSpan.parentSpanId = int(span['psid'])

        if 'tid' in span:
            tSpan.transactionId = TransactionId(
                encoded_str=span['tid']).getBytes()

        if 'sid' in span:
            tSpan.spanId = int(span['sid'])

        if 'S' in span:
            tSpan.startTime = span['S']

        if 'E' in span:
            tSpan.elapsed = span['E']

        if 'uri' in span:
            tSpan.rpc = span['uri']

        if 'pname' in span:
            tSpan.parentApplicationName = span['pname']

        if 'ptype' in span:
            tSpan.parentApplicationType = int(span['ptype'])

        if 'client' in span:
            tSpan.remoteAddr = span['client']

        if 'server' in span:
            tSpan.endPoint = span['server']

        if 'ERR' in span:
            tSpan.err = 1
            id = interceptManger.updateStringMeta('ERR').apiId
            tSpan.exceptionInfo = TIntStringValue(id, span['ERR']['msg'])

        if 'Ah' in span:
            tSpan.acceptorHost = span['Ah']

        tSpan.spanEventList = []
        tSpan.annotations = []

        if 'clues' in span:
            for annotation in span['clues']:  # list
                id, value = annotation.split(':', 1)
                ann = TAnnotation(int(id), TAnnotationValue(stringValue=value))
                tSpan.annotations.append(ann)

        try:
            value = TLongIntIntByteByteStringValue()
            if 'NP' in span:  ## nginx
                arr = ConvertSpan._parseStrField(span['NP'])
                value.intValue1 = 2
                if 'D' in arr:
                    value.intValue2 = ConvertSpan._parseDotFormat(arr['D'])
                if 't' in arr:
                    value.longValue = ConvertSpan._parseDotFormat(arr['t'])
            elif 'AP' in span:  ## apache
                arr = ConvertSpan._parseStrField(span['AP'])
                value.intValue1 = 3
                if 'i' in arr:
                    value.byteValue1 = int(arr['i'])
                if 'b' in arr:
                    value.byteValue2 = int(arr['b'])
                if 'D' in arr:
                    value.intValue2 = int(arr['D'])
                if 't' in arr:
                    value.longValue = int(int(arr['t']) / 1000)
            ann = TAnnotation(
                PROXY_HTTP_HEADER,
                TAnnotationValue(longIntIntByteByteStringValue=value))
            tSpan.annotations.append(ann)
        except Exception as e:
            TCLogger.error("input is illegal,Exception %s", e)

        return tSpan