Search in sources :

Example 1 with Line

use of com.creditease.agent.apm.api.CollectDataFrame.Line in project uavstack by uavorg.

the class ThreadAnalysisCollectDataHandler method analyse.

/**
 * 线程分析文件信息处理方法
 *
 * @param list
 * @return
 */
private List<JavaThreadObject> analyse(List<Line> list) {
    long stTime = System.currentTimeMillis();
    // 初始化top命令部分的线程list对象
    List<JavaThreadObject> topJavaThreadObjectList = new ArrayList<JavaThreadObject>();
    // 初始化jstack命令部分的线程list对象
    List<JavaThreadObject> jstackJavaThreadObjectList = new ArrayList<JavaThreadObject>();
    // 将top命令部分的threadObject和jstack命令部分的threadObject利用tid关联成同一个threadObject对象
    List<JavaThreadObject> JavaThreadObjectList = new ArrayList<JavaThreadObject>();
    // top命令获取的列名称map,key为序号,value为列名称
    Map<String, Integer> lables = new HashMap<String, Integer>();
    HANDLE_STATUS status = HANDLE_STATUS.IGNORE;
    // 定义jstackJavaThreadObject对象,初始为null
    JavaThreadObject jstackJavaThreadObject = null;
    // 定义jstatckInfo对象,初始为null
    StringBuffer jstatckInfo = null;
    // 开始循环遍历lines
    for (Line collectLine : list) {
        // 获取单行字符串
        String line = collectLine.getContent();
        if ("=====".equals(line)) {
            status = HANDLE_STATUS.IGNORE;
            continue;
        }
        if (StringHelper.isEmpty(line)) {
            if (HANDLE_STATUS.TOP.equals(status)) {
                status = HANDLE_STATUS.IGNORE;
            } else if (HANDLE_STATUS.JSTATCK.equals(status)) {
                status = HANDLE_STATUS.ADDINFO;
            }
        } else if (line.contains("PID")) {
            // 利用空字符串进行分割,分割的每项为top命令的列名称,将列名称保存入循环外部定义的map
            String[] cells = line.trim().split("\\s+");
            for (int i = 0; i < cells.length; i++) {
                lables.put(cells[i], i);
            }
            status = HANDLE_STATUS.TOP;
            continue;
        } else if (isJStackInfo(line)) {
            // 初始化jstackJavaThreadObject对象
            jstackJavaThreadObject = new JavaThreadObject();
            // 初始化jstatckInfo对象
            jstatckInfo = new StringBuffer();
            // 捕获nid值,前两位表示进制(16位),后面表示值
            Pattern pattern = Pattern.compile("nid=([0-9,a-z]*)");
            Matcher matcher = pattern.matcher(line);
            if (matcher.find()) {
                // 获取16位进制线程号
                String tid = matcher.group().replace("nid=0x", "");
                // 转换为十进制的线程号
                BigInteger srch = new BigInteger(tid, 16);
                // 保存线程号
                jstackJavaThreadObject.setTid(srch.toString().trim());
            }
            status = HANDLE_STATUS.JSTATCK;
        }
        /**
         * begin to handle message
         */
        if (HANDLE_STATUS.TOP.equals(status)) {
            analyseTopPart(topJavaThreadObjectList, lables, line);
        } else if (HANDLE_STATUS.JSTATCK.equals(status)) {
            analyseJstackPart(jstackJavaThreadObject, jstatckInfo, line);
        } else if (HANDLE_STATUS.ADDINFO.equals(status)) {
            // 保存线程栈信息对象jstatckInfo
            jstackJavaThreadObject.setInfo(jstatckInfo.toString());
            // 将jstackJavaThreadObject添加到jstackJavaThreadObjectList
            jstackJavaThreadObjectList.add(jstackJavaThreadObject);
            status = HANDLE_STATUS.IGNORE;
        }
    }
    mergeJavaThreadObject(JavaThreadObjectList, topJavaThreadObjectList, jstackJavaThreadObjectList);
    long elapse = System.currentTimeMillis() - stTime;
    log.info(this, "thread analyse costs: " + elapse + " ms.");
    return JavaThreadObjectList;
}
Also used : Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) JavaThreadObject(com.creditease.uav.threadanalysis.data.JavaThreadObject) BigInteger(java.math.BigInteger) Line(com.creditease.agent.apm.api.CollectDataFrame.Line) BigInteger(java.math.BigInteger)

Example 2 with Line

use of com.creditease.agent.apm.api.CollectDataFrame.Line in project uavstack by uavorg.

the class SlowOperDataCollectHandler method handle.

@Override
public void handle(CollectDataFrame frame) {
    if (this.log.isDebugEnable()) {
        this.log.debug(this, frame.toJSONString());
    }
    BulkRequestBuilder bulkRequest = client.getClient().prepareBulk();
    String appUUID = frame.getTarget();
    // 从uuid中获取appid
    String appid = appUUID.split("---")[1];
    for (Line line : frame.getLines()) {
        String content = line.getContent();
        try {
            // 提取epinfo
            StringBuilder builder = new StringBuilder();
            int headPoint = 0;
            for (int i = 0; i < content.length(); i++) {
                char item = content.charAt(i);
                if (item == ';') {
                    headPoint++;
                    if (headPoint == 3) {
                        break;
                    }
                } else {
                    if (headPoint > 1) {
                        builder.append(item);
                    }
                }
            }
            String epinfo = builder.toString();
            // 若epinfo为数字则说明为方法级
            if (DataConvertHelper.toInt(epinfo, -1) != -1) {
                epinfo = "method";
            }
            IActionEngine engine = this.getActionEngineMgr().getActionEngine("SlowOperActionEngine");
            ActionContext ac = new ActionContext();
            ac.putParam("content", content);
            ac.putParam("appid", appid);
            engine.execute(epinfo, ac);
            SlowOperSpan span = (SlowOperSpan) ac.getParam("span");
            pushSpanToBulkRequest(appUUID, frame.getAppgroup(), span, bulkRequest, (String) ac.getParam("protocolType"));
        } catch (Exception e) {
            // 防止有不合法的协议报文出现
            this.log.err(this, "unsupported protocol,content is" + frame.toJSONString(), e);
        }
    }
    BulkResponse bulkResponse = bulkRequest.get();
    if (bulkResponse.hasFailures()) {
        log.err(this, "INSERT InvokeChain Data to ES FAIL: " + bulkResponse.buildFailureMessage());
    }
}
Also used : Line(com.creditease.agent.apm.api.CollectDataFrame.Line) SlowOperSpan(com.creditease.uav.invokechain.data.SlowOperSpan) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) ActionContext(com.creditease.agent.spi.ActionContext) IActionEngine(com.creditease.agent.spi.IActionEngine)

Example 3 with Line

use of com.creditease.agent.apm.api.CollectDataFrame.Line in project uavstack by uavorg.

the class InvokeChainDataCollectHandler method handle.

@Override
public void handle(CollectDataFrame frame) {
    if (this.log.isDebugEnable()) {
        this.log.debug(this, frame.toJSONString());
    }
    String appUUID = frame.getTarget();
    // cm.beginBatch();
    BulkRequestBuilder bulkRequest = client.getClient().prepareBulk();
    for (Line line : frame.getLines()) {
        String content = line.getContent();
        Span span = new Span(content);
        pushLatestIVCDataToCache(appUUID, span);
        pushSpanToBulkRequest(appUUID, frame.getAppgroup(), span, bulkRequest);
    }
    // cm.submitBatch();
    BulkResponse bulkResponse = bulkRequest.get();
    if (bulkResponse.hasFailures()) {
        log.err(this, "INSERT InvokeChain Data to ES FAIL: " + bulkResponse.buildFailureMessage());
    }
}
Also used : Line(com.creditease.agent.apm.api.CollectDataFrame.Line) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder) Span(com.creditease.uav.invokechain.data.Span)

Example 4 with Line

use of com.creditease.agent.apm.api.CollectDataFrame.Line in project uavstack by uavorg.

the class ThreadAnalysisCollectDataHandler method handle.

/**
 * 数据归集feature消费者消息接收方法
 */
@Override
public void handle(CollectDataFrame frame) {
    if (this.log.isDebugEnable()) {
        this.log.debug(this, frame.toJSONString());
    }
    // 线程分析文件按次生成,一次采集完,应该在一个 CollectDataFrame 中
    if (!frame.isEof()) {
        return;
    }
    /**
     * TODO:pname到底从哪获得呢?
     */
    String pname = "";
    String appgroup = frame.getAppgroup();
    String appUUID = frame.getTarget();
    String[] target = appUUID.split("_");
    // 获取数据归集feature的消费信息,frame为一条消费信息,从fame中获取lines为线程分析文件的消费信息
    List<Line> list = frame.getLines();
    // 调用线程分析文件信息处理方法
    List<JavaThreadObject> result = analyse(list);
    /**
     * add additional information: pname,ipport,pid,appgroup,time,user
     */
    for (JavaThreadObject jto : result) {
        jto.setPname(pname);
        jto.setIpport(target[0]);
        jto.setPid(target[1]);
        jto.setAppgroup(appgroup);
        jto.setTime(Long.parseLong(target[2]));
        jto.setUser(target[3]);
    }
    // 处理数据保存工作
    insertThreadObjectToES(result);
}
Also used : Line(com.creditease.agent.apm.api.CollectDataFrame.Line) JavaThreadObject(com.creditease.uav.threadanalysis.data.JavaThreadObject)

Aggregations

Line (com.creditease.agent.apm.api.CollectDataFrame.Line)4 JavaThreadObject (com.creditease.uav.threadanalysis.data.JavaThreadObject)2 BulkRequestBuilder (org.elasticsearch.action.bulk.BulkRequestBuilder)2 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)2 ActionContext (com.creditease.agent.spi.ActionContext)1 IActionEngine (com.creditease.agent.spi.IActionEngine)1 SlowOperSpan (com.creditease.uav.invokechain.data.SlowOperSpan)1 Span (com.creditease.uav.invokechain.data.Span)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1