查看 Agent启动日志是发现错误日志如下:
AbstractClassEnhancePluginDefine : enhance class xxx by plugin xxx is not working. Because witness class xxx is not existed.
WARN 2020-07-24 18:37:27:857 AsyncAppender-Worker-ASYNC_KAFKA AbstractClassEnhancePluginDefine : enhance class org.apache.kafka.clients.producer.KafkaProducer$InterceptorCallback by plugin org.apache.skywalking.apm.plugin.kafka.define.KafkaTemplateCallbackInstrumentation is not working. Because witness class org.springframework.kafka.core.KafkaTemplate is not existed.
WARN 2020-07-24 18:37:33:081 main AbstractClassEnhancePluginDefine : enhance class org.springframework.web.method.HandlerMethod by plugin org.apache.skywalking.apm.plugin.spring.mvc.v3.define.HandlerMethodInstrumentation is not working. Because witness class org.springframework.web.servlet.view.xslt.AbstractXsltView is not existed.
WARN 2020-07-24 18:37:33:081 main AbstractClassEnhancePluginDefine : enhance class org.springframework.web.method.HandlerMethod by plugin org.apache.skywalking.apm.plugin.spring.mvc.v4.define.HandlerMethodInstrumentation is not working. Because witness class org.springframework.cache.interceptor.DefaultKeyGenerator is not existed.
WARN 2020-07-24 18:37:33:081 main AbstractClassEnhancePluginDefine : enhance class org.springframework.web.method.HandlerMethod by plugin org.apache.skywalking.apm.plugin.spring.mvc.v5.define.HandlerMethodInstrumentation is not working. Because witness class org.springframework.web.servlet.resource.HttpResource is not existed.
意思是指在skywalking Agent在加载apm插件时,没有在监听工程中找到对应的jar包。
- 方案一:如果确实没有用到响应的插件,或者不需要监控相关组件,就可以可以将agent/plugins目录下对应的apm包移到agent/optional-plugins下,这样在agent启动时就不会加载。
- 方案二:如果确实需要用到apm插件,就需要在所需要监控的工作中引入响应的组件包。
比如我上面的日志:
- 日志显示apm spring mvc v3、v4、v5加载时springmvc相关类不存在,因为我用的spring5,使用的是web-flux,所以没有springmvc相关jar包,因此我将agent/plugins包下的apm-springmvc-annotation-3.x-plugin-8.0.1.jar、apm-springmvc-annotation-4.x-plugin-8.0.1.jar、apm-springmvc-annotation-5.x-plugin-8.0.1.jar移动到了agent/optional-plugins下。
- 在加载kafka插件式发现缺少KafkaTemplate类,因为我这用的是ELK组件,没有引入spring-kafka包,因为我需要对kafka相关信息监控,这里我再工程中引入spring-kafka即可。
做完以上调整,启动无异常