Getting ECONNREFUSED when calling from Node

Hello,
We are trying to explore APM and have setup Kibana, Elastic, and an APM Server Containers. In doing so, we have gotten the Kibana Server up, the Elastic Server talking to Kibana and it appears to be recognizing the APM Server. 'Check APM Server status' from Kibana says success. This message is questionable, because when the container is paused - the message still says success.

When we attempt to send data to the APM Server from Node, we receive an Error: connect ECONNREFUSED message. We are using the hapi framework and the following call is made in index.js before the server starts.

var apm = require('elastic-apm-node').start({
    serviceName: 'apm-test-service',
    secretToken: '',
    serverUrl: '[name-of-server-removed]:42000',
  });

we receive a logging error message but eventually receive the following message
Error: connect ECONNREFUSED [ip-address-removed]:42000
    at Object._errnoException (util.js:1031:13)
    at _exceptionWithHostPort (util.js:1052:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1195:14)

Also, may be helpful:
our apm-server.yml file looks like

output.elasticsearch:
 hosts: ['[removed-the-server-name]:9200']

Elastic is in development mode.

Any help is appreciated...thanks!

1 Like

That seems odd. Could I get you to curl the APM Server to see that it responds like expected to HTTP requests?

Try to run the following command:

curl -v <hostname>:42000/v1/transactions

You should see something like this:

*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8200 (#0)
> GET /v1/transactions HTTP/1.1
> Host: localhost:8200
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 405 Method Not Allowed
< Content-Type: application/json
< Date: Fri, 20 Apr 2018 19:33:31 GMT
< Content-Length: 44
<
* Connection #0 to host localhost left intact
{"error":"only POST requests are supported"}% 

Same here... using 3 Docker services in a swarm named respectively elasticsearch, kibana and apm. The first two are in the "elk" network, apm being both in the "elk" and "services" network. The goal is to create services being able to access apm, but no elasticsearch or kibana.

No problem whatsoever communicating from kibana to elasticsearch. It is reachable using http://elasticsearch:9200 and kibana can query it.

Same goes for apm output. When apm starts, logs show up to that effect in elasticsearch.

Problem is... node apps in the "services" network should be able to access apm via http://apm:8200 but they don't. The api responds inside an apm container, but no way to access it from any other container or even by the host system, which is configured to publish port 8200.

Question is... does apm from docker.elastic.co/apm/apm-server:6.2.4 only accepts HTTP requests from localhost?

Just to be clear, also using docker.elastic.co/elasticsearch/elasticsearch-basic:6.2.4 and docker.elastic.co/kibana/kibana-x-pack:6.2.4 for the other two services.

Hi!

Yes, The APM Server docker image only listens on localhost:8200 by default.
We should probably change that, so it will listen on any interface by default.

In the mean time, to connect to APM Server from the outside, you'll need to pass this setting:

docker run -p 8200:8200 docker.elastic.co/apm/apm-server:6.2.4 -e -E apm-server.host=0.0.0.0:8200

Hope that helps!

best,
Ron

5 Likes

Working, thank you very much!

Really have to use the executable's -E flag and not a docker environment variable, though.

That thread makes me wonder what's the use for a Docker service not accepting outside requests.

This is working for me as well!

Thank you!

Starting with APM Server 6.3, the docker image configure APM Server to listen on all interfaces by default. See this PR for more info: https://github.com/elastic/apm-server-docker/pull/16

1 Like

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