# Automatic APM agent cannot connect to apm server

**URL:** <https://discuss.elastic.co/t/automatic-apm-agent-cannot-connect-to-apm-server/268723>\
**Category:** APM\
**Tags:** java\
**Created:** [March 30, 2021, 4:36am UTC](https://discuss.elastic.co/t/automatic-apm-agent-cannot-connect-to-apm-server/268723 "2021-03-30T04:36:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Christopher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevin_christopher/32/86261_2.png) [@Kevin\_Christopher](https://discuss.elastic.co/u/Kevin_Christopher)\
**Post date:** [March 30, 2021, 4:36am UTC](https://discuss.elastic.co/t/automatic-apm-agent-cannot-connect-to-apm-server/268723/1 "2021-03-30T04:36:06Z")

</div>

**Kibana version** : 7.12

**Elasticsearch version** : 7.12

**APM Server version** : 7.12

**APM Agent language and version** : Java 1.22

**Browser version** : Chrome 86

**Original install method (e.g. download page, yum, deb, from source, etc.) and version**: source

**Fresh install or upgraded from other version?** fresh

**Is there anything special in your setup?** For example, are you using the Logstash or Kafka outputs? Are you using a load balancer in front of the APM Servers? Have you changed index pattern, generated custom templates, changed agent configuration etc.  
No  
There are no SSL/TLS enabled and disabled the firewall too  
SSL disabled in apm-server.yml too

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**:

I have ELK stack with Apm-server in one ec2 instance and installed java apm-agent for monitoring jenkins in another ec2 instance

I followed the automatic setup for apm-agent

Command used:

```auto
java -jar apm-agent-attach-standalone.jar --include '.*jenkins.*' --config service_name=jenkins-service --config server_url=http://privateipofapmserver:8200

```

I can curl the apm-server instance and got 200 response

**Steps to reproduce** :

1. Started Jenkins service  
2.Execute the command  
3.Check output

**Errors in browser console (if relevant)**:

```auto
2021-03-30 03:52:59.425 INFO Attaching the Elastic APM agent to 7816 /usr/share/jenkins/jenkins.war -Djava.awt.headless=true with arguments {service_name=jenkins-service, server_url=http://x.x.x.x:8200}
2021-03-30 03:53:20.638 INFO Done
jenkins@ip-x.x.x.x:/etc/apmagents$ java -jar apm-agent-attach-standalone.jar --list
7816 /usr/share/jenkins/jenkins.war -Djava.awt.headless=true
24190 apm-agent-attach-standalone.jar

```

**Provide logs and/or server output (if relevant)**:  
1.No errors in apm-server log  
2.Error in jenkins.log

```auto
2021-03-30 04:31:11,928 [elastic-apm-server-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Error trying to connect to APM Server. Some details about SSL configurations corresponding the current connection are logged at INFO level.
2021-03-30 04:31:11,928 [elastic-apm-server-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Failed to handle event of type TRANSACTION with this error: Connection refused (Connection refused)
2021-03-30 04:31:11,928 [elastic-apm-server-reporter] INFO co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 36 seconds (+/-10%)

```

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [March 30, 2021, 8:53am UTC](https://discuss.elastic.co/t/automatic-apm-agent-cannot-connect-to-apm-server/268723/2 "2021-03-30T08:53:02Z")

</div>

Hi @Kevin_Christopher,

You should set the agent configuration `log_level=debug` to enable more detailed logging of the possible reasons the APM agent can't reach the server.

As the agent log will be more verbose, you might also set `log_file` to log to an external file so it won't pollute your jenkins logs.

See [logging documentation reference](https://www.elastic.co/guide/en/apm/agent/java/current/config-logging.html#config-logging) for more details.

---

<div class="post-metadata">

**Author:** ![Kevin\_Christopher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevin_christopher/32/86261_2.png) [@Kevin\_Christopher](https://discuss.elastic.co/u/Kevin_Christopher)\
**Post date:** [March 30, 2021, 10:22am UTC](https://discuss.elastic.co/t/automatic-apm-agent-cannot-connect-to-apm-server/268723/3 "2021-03-30T10:22:12Z")

</div>

Hi @Sylvain_Juge ,

Thanks for the quick response.

Actually I repeated the steps for new jenkins server. It worked.  
However I am not sure where to add the configuration log\_level=debug and log\_file.I tried with below command and file not created.

As you mentioned not to pollute the application log, your details will help

Can you explain it a bit more of where to setup this?

```auto
java -jar apm-agent-attach-standalone.jar --include '.*jenkins.*' --config service_name=jenkins-service --config server_url=http://x.x.x.x:8200 --config elastic.apm.log_file=/var/log/apm.log --config log_level=debug

```

---

<div class="post-metadata">

**Author:** ![Sylvain\_Juge](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sylvain_juge/32/55521_2.png) [@Sylvain\_Juge](https://discuss.elastic.co/u/Sylvain_Juge)\
**Post date:** [March 30, 2021, 11:50am UTC](https://discuss.elastic.co/t/automatic-apm-agent-cannot-connect-to-apm-server/268723/4 "2021-03-30T11:50:57Z")

</div>

When using the `--config` option, you don't have the use the `elastic.apm.` prefix, thus if you remove it the following should work:

```auto
java -jar apm-agent-attach-standalone.jar --include '.*jenkins.*' --config service_name=jenkins-service --config server_url=http://x.x.x.x:8200 --config log_file=/var/log/apm.log --config log_level=debug

```

> **[Automatic setup with apm-agent-attach-standalone.jar | APM Java Agent...](https://www.elastic.co/guide/en/apm/agent/java/current/setup-attach-cli.html#setup-attach-cli-usage-filtered)**

---

<div class="post-metadata">

**Author:** ![Kevin\_Christopher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevin_christopher/32/86261_2.png) [@Kevin\_Christopher](https://discuss.elastic.co/u/Kevin_Christopher)\
**Post date:** [March 30, 2021, 2:36pm UTC](https://discuss.elastic.co/t/automatic-apm-agent-cannot-connect-to-apm-server/268723/5 "2021-03-30T14:36:49Z")

</div>

@Sylvain_Juge  
Thank you very much

---

<div class="post-metadata">

**Author:** ![Kevin\_Christopher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevin_christopher/32/86261_2.png) [@Kevin\_Christopher](https://discuss.elastic.co/u/Kevin_Christopher)\
**Post date:** [April 5, 2021, 5:52am UTC](https://discuss.elastic.co/t/automatic-apm-agent-cannot-connect-to-apm-server/268723/6 "2021-04-05T05:52:02Z")

</div>

@Sylvain_Juge

When I use the below command ,I am not getting any logs in new log file and jenkins.log too but data is received in apmserver and kibana. log levels are also not changing.

```auto
java -jar apm-agent-attach-standalone.jar --include '.*jenkins.*' --config service_name=jenkins-service --config server_url=http://x.x.x.x:8200 --config log_file=/var/log/apm.log --config log_level=debug

```

**response:**

```auto
2021-04-05 05:43:05.089 INFO Attaching the Elastic APM agent to 27602 /usr/share/jenkins/jenkins.war -Djava.awt.headless=true with arguments {service_name=jenkins-service, server_url=http://x.x.x.x:8200}
2021-04-05 05:43:05.545 INFO Done

```

**Note:**  
No errors in apm-server,jenkins,apm-agent

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 26, 2021, 1:52am UTC](https://discuss.elastic.co/t/automatic-apm-agent-cannot-connect-to-apm-server/268723/7 "2021-04-26T01:52:24Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
