当Java APM代理在Docker中运行时,如何将Java APM代理连接到APM服务器?



我想在Docker内运行Java APM代理在docker组件中,我得到以下错误消息:

2021-08-23 08:13:52,481 [elastic-apm-server-healthcheck] WARN  co.elastic.apm.agent.report.ApmServerHealthChecker - Elastic APM server https://i-o-optimized-deployment-912238.es.us-west1.gcp.cloud.es.io:9243/ is not available (Server returned status 401)
2021-08-23 08:13:52,779 [elastic-apm-remote-config-poller] ERROR co.elastic.apm.agent.configuration.ApmServerConfigurationSource - Unexpected status 401 while fetching configuration

Dockerfiles看起来像这样

FROM gradle as gradleimage
COPY ./app /home/gradle/source/app
COPY settings.gradle /home/gradle/source/settings.gradle
WORKDIR /home/gradle/source
RUN gradle assemble
EXPOSE 5000
FROM openjdk
COPY --from=gradleimage /home/gradle/source/app/build/libs/app.jar /app/
COPY ./apmplugin/elastic-apm-agent-1.25.0.jar /app/
WORKDIR /app
ENTRYPOINT ["java",  "-javaagent:elastic-apm-agent-1.25.0.jar", "-Delastic.apm.service_name=helloworld","-Delastic.apm.server_urls=https://i-o-optimized-deployment-912238.es.us-west1.gcp.cloud.es.io:9243", "-Delastic.apm.api_key= xxxxxxx" ,"-Delastic.apm.application_packages=org.steinko.helloworld",  "-jar", "app.jar"]

docker运行命令返回这个

steinko@Steins-MacBook-Pro ci-cd-template % docker run -t -p 5000:5000  steinko/helloworld 
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
2021-08-23 08:13:50,953 [main] INFO  co.elastic.apm.agent.util.JmxUtils - Found JVM-specific OperatingSystemMXBean interface: com.sun.management.OperatingSystemMXBean
2021-08-23 08:13:50,972 [main] INFO  co.elastic.apm.agent.configuration.StartupInfo - Starting Elastic APM 1.25.0 as helloworld on Java 16.0.2 Runtime version: 16.0.2+7-67 VM version: 16.0.2+7-67 (Oracle Corporation) Linux 5.10.25-linuxkit
2021-08-23 08:13:50,973 [main] INFO  co.elastic.apm.agent.configuration.StartupInfo - service_name: 'helloworld' (source: Java System Properties)
2021-08-23 08:13:50,973 [main] INFO  co.elastic.apm.agent.configuration.StartupInfo - api_key: 'XXXX' (source: Java System Properties)
2021-08-23 08:13:50,973 [main] INFO  co.elastic.apm.agent.configuration.StartupInfo - server_urls: 'https://i-o-optimized-deployment-912238.es.us-west1.gcp.cloud.es.io:9243' (source: Java System Properties)
2021-08-23 08:13:50,973 [main] INFO  co.elastic.apm.agent.configuration.StartupInfo - application_packages: 'org.steinko.helloworld' (source: Java System Properties)
2021-08-23 08:13:51,389 [main] INFO  co.elastic.apm.agent.impl.ElasticApmTracer - Tracer switched to RUNNING state
.   ____          _            __ _ _
/\ / ___'_ __ _ _(_)_ __  __ _    
( ( )___ | '_ | '_| | '_ / _` |    
\/  ___)| |_)| | | | | || (_| |  ) ) ) )
'  |____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot ::                (v2.4.5)
2021-08-23 08:13:51.968  INFO 1 --- [           main] org.steinko.helloworld.App               : Starting App using Java 16.0.2 on 0f3c5bf51643 with PID 1 (/app/app.jar started by root in /app)
2021-08-23 08:13:51.973  INFO 1 --- [           main] org.steinko.helloworld.App               : No active profile set, falling back to default profiles: default
2021-08-23 08:13:52,481 [elastic-apm-server-healthcheck] WARN  co.elastic.apm.agent.report.ApmServerHealthChecker - Elastic APM server https://i-o-optimized-deployment-912238.es.us-west1.gcp.cloud.es.io:9243/ is not available (Server returned status 401)
2021-08-23 08:13:52,779 [elastic-apm-remote-config-poller] ERROR co.elastic.apm.agent.configuration.ApmServerConfigurationSource - Unexpected status 401 while fetching configuration
2021-08-23 08:13:52.970  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 5000 (http)
2021-08-23 08:13:52.982  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-08-23 08:13:52.982  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.45]
2021-08-23 08:13:53.019  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-08-23 08:13:53.019  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1016 ms
2021-08-23 08:13:53,048 [main] INFO  co.elastic.apm.agent.micrometer.MicrometerMetricsReporter - Registering Micrometer MeterRegistry: io.micrometer.core.instrument.simple.SimpleMeterRegistry@7593ea79
2021-08-23 08:13:53.451  INFO 1 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 14 endpoint(s) beneath base path '/actuator'
2021-08-23 08:13:53.524  INFO 1 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-08-23 08:13:53.688  INFO 1 --- [           main] .s.s.UserDetailsServiceAutoConfiguration : 
Using generated security password: c9f8d5ae-61d5-4410-b99c-bcecbf3593de
2021-08-23 08:13:53.776  INFO 1 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Will secure any request with [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@6af310c7, org.springframework.security.web.context.SecurityContextPersistenceFilter@291a4791, org.springframework.security.web.header.HeaderWriterFilter@1d289d3f, org.springframework.security.web.csrf.CsrfFilter@34045582, org.springframework.security.web.authentication.logout.LogoutFilter@349c4d1c, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@46394f65, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@340cb97f, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@4a216eb4, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@4aed311e, org.springframework.security.web.session.SessionManagementFilter@3520958b, org.springframework.security.web.access.ExceptionTranslationFilter@44d7e24, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@75eaba95]
2021-08-23 08:13:53.824  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 5000 (http) with context path ''
2021-08-23 08:13:54.034  INFO 1 --- [           main] org.steinko.helloworld.App               : Started App in 2.376 seconds (JVM running for 3.354)
2021-08-23 08:14:32,106 [elastic-apm-server-reporter] INFO  co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 0 seconds (+/-10%)
2021-08-23 08:14:32,110 [elastic-apm-server-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Error sending data to APM server: cannot retry due to server authentication, in streaming mode, response code is 401
2021-08-23 08:14:32,111 [elastic-apm-server-reporter] WARN  co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - null

连接APM服务器需要做什么?

可能是您尝试向api_key配置选项提供一个秘密令牌。这不是一回事。试试用-Delastic.apm.secret_token=xxxxxxx代替-Delastic.apm.api_key=xxxxxxx

查看APM Server文档了解更多不同之处。

也抛出,看起来你的server_urls指向一个Elasticsearch URL &不是APM URL

我希望APM服务器URL格式为https://i-o-optimized-deployment-912238.apm.us-west1.gcp.cloud.es.io(基于您当前的Elasticsearch URLhttps://i-o-optimized-deployment-912238.es.us-west1.gcp.cloud.es.io:9243)。

HTTPs Elasticsearch将HTTP401错误w/o身份验证,但您可能能够在您的设置APM URL走得更远。

最新更新