0

Spring Insight文档指出:

一个跟踪代表一个执行线程。它通常由 HTTP 请求启动,但也可以由后台作业启动

我的应用程序架构风格是在后台运行的队列之一,我也想对其进行检测。但是,我不知道如何让 Spring Insight 检测这些由排队消息发起的调用。即,我想在从队列中读取消息后检测跟踪。

如何确保 Insight 检测这些后台作业?

4

1 回答 1

0

我最终创建了一个面向所有命令处理程序的方面。它扩展了AbstractOperationCollectionAspect,实现了collectionPoint在 Handler 中作为参数传递的方面,以便在实现createOperation方法时使用。
IE

public aspect CommandHandlerOperationCollectionAspect extends AbstractOperationCollectionAspect
{

    public pointcut collectionPoint():
            execution(* com.xtrac.common.core.handler.ThreadedHandler.HandlerRunnable.executeActorHandler(com.xtrac.common.core.handler.Handler,java.lang.Object));


    protected Operation createOperation(JoinPoint jp)
    {
        Object[] args = jp.getArgs();
        com.xtrac.common.core.handler.Handler handler = (Handler) args[0];
        Operation operation = new Operation()
                .type(XTRACOperationType.COMMAND_HANDLER)
                .label(handler.getClass().getSimpleName())
                .sourceCodeLocation(getSourceCodeLocation(jp));
        return operation;
    }

    @Override
    public String getPluginName()
    {
        return HandlerPluginRuntimeDescriptor.PLUGIN_NAME;
    }

    @Override
    public boolean isMetricsGenerator()
    {
        return true;
    }
}

我还实现了一个AbstractSingleTypeEndpointAnalyzer填写分析器: public class HandlerEndPointAnalyzer extends AbstractSingleTypeEndpointAnalyzer { private static final HandlerEndPointAnalyzer INSTANCE=new HandlerEndPointAnalyzer();

    private HandlerEndPointAnalyzer() {
        super(XTRACOperationType.COMMAND_HANDLER);
    }

    public static final HandlerEndPointAnalyzer getInstance() {
        return INSTANCE;
    }

    @Override
        protected EndPointAnalysis makeEndPoint(Frame handlerFrame, int depth) {
            Operation operation = handlerFrame.getOperation();
    String resourceLabel = operation.getLabel();
    String exampleRequest = EndPointAnalysis.getHttpExampleRequest(handlerFrame);
    return new EndPointAnalysis(EndPointName.valueOf(resourceLabel),
                                resourceLabel,
                                exampleRequest,
                                getOperationScore(operation, depth),
                                operation);
}

确保将其添加为描述符:

public class HandlerPluginRuntimeDescriptor extends PluginRuntimeDescriptor {
    public static final String PLUGIN_NAME = "handler";
    private static final HandlerPluginRuntimeDescriptor INSTANCE=new HandlerPluginRuntimeDescriptor();
    private static final List<? extends EndPointAnalyzer>   epAnalyzers=
            ArrayUtil.asUnmodifiableList(HandlerEndPointAnalyzer.getInstance());

    private HandlerPluginRuntimeDescriptor() {
        super();
    }

    public static final HandlerPluginRuntimeDescriptor getInstance() {
        return INSTANCE;
    }

    @Override
    public Collection<? extends EndPointAnalyzer> getEndPointAnalyzers() {
        return epAnalyzers;
    }

    @Override
    public String getPluginName() {
        return PLUGIN_NAME;
    }
}

所有在 spring xml 文件中记录:

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:insight="http://www.springframework.org/schema/insight-idk"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/insight-idk http://www.springframework.org/schema/insight-idk/insight-idk-1.0.xsd">

  <insight:plugin name="handler" version="${project.version}" publisher="XTRAC Solutions LLC" />


  <insight:operation-group group="XTRAC Handlers" operation="command_handler_operation" />
  <insight:operation-group group="XTRAC Handlers" operation="event_handler_operation" />
  <insight:operation-group group="XTRAC Classic" operation="xtrac_workflow_operation" />

  <insight:operation-view operation="command_handler_operation"
                          template="com/xtrac/insight/command_handler_operation.ftl" />
  <insight:operation-view operation="event_handler_operation"
                          template="com/xtrac/insight/event_handler_operation.ftl" />
  <insight:operation-view operation="xtrac_workflow_operation"
                          template="com/xtrac/insight/xtrac_workflow_operation.ftl" />

    <bean id="handlerPluginEndPointAnalyzer"
          class="com.xtrac.insight.HandlerEndPointAnalyzer"
          factory-method="getInstance"
          lazy-init="true"
        />
    <bean id="handlerPluginRuntimeDescriptor"
             class="com.xtrac.insight.HandlerPluginRuntimeDescriptor"
             factory-method="getInstance"
             lazy-init="true"
           />

</beans>

连同一些ftls。

我还创建了一个MethodOperationCollectionAspect来收集这些处理程序中发生的一些 Web 服务调用。这设置了一个很好的显示,告诉我很多关于hander操作过程中发生的事情,以及需要多少时间。例如 混合了 Web 服务调用的 Spring 处理程序示例

如果我为命名处理程序设置基线阈值,这将设置一个框架来维护应用程序的运行状况监视器

门槛

这非常有用,因为我可以判断应用程序是否健康。否则,端点默认为 <200 毫秒以表示健康。
健康

于 2014-05-15T13:34:27.153 回答