Docker Filebeat 7.9.3 cannot collect metrics from http from outside the container

Hello Elastic Staff
I am not able to collect metrics from filebeat from the defined http port.
I can get the metrics from within the filebeat container with curl -XGET localhost:5066/stats.
When I want to collect the metrics from my machine I get the message "Empty reply from server". The container port is published to the host at port 5066.

My Configuration:
filebeat.yml

http.enabled: true
http.port: 5066

filebeat.config:
  modules:
    path: ${path.config}/modules.d/*.yml
    reload.enabled: false

filebeat.autodiscover:
  providers:
    - type: docker
      hints.enabled: true

processors:
- add_cloud_metadata: ~

output.elasticsearch:
  hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
  username: '${ELASTICSEARCH_USERNAME:}'
  password: '${ELASTICSEARCH_PASSWORD:}'

Start filebeat by command:

docker run -p "5066:5066"   --name=filebeat   --user=root   --volume="$(pwd)/filebeat.docker.yml:/usr/share/filebeat/filebeat.yml:ro"   --volume="/var/lib/docker/containers:/var/lib/docker/containers:ro"   --volume="/var/run/docker.sock:/var/run/docker.sock:ro" docker.elastic.co/beats/filebeat:7.9.3 filebeat -e -strict.perms=false

Run curl -XGET http://localhost:5066/stats from my machine with the response: "curl: (52) Empty reply from server". Here I want to get the

Is there something missing that it won't work?

Best

Hi!

Can you try the curl command from inside the container to check that the endpoint is actually enabled?

Also maybe a redirection takes place so you could try adding some extra flags like -sS or -L.

Let me know if that helps.

C.

Hi,
thanks for your reply. I tried it from inside the container and got a response. So the endpoint should work.

I tried to run curl with the flags -sS and -L on my machine but the response is as before "Empty reply from server".

Hmm,

this is weird. Can you try with 0.0.0.0 instead of localhost?

This also did not help. I now also set explicitly server.host: "0". But also no change of the result.

Ok I found the solution. I missed to set the variable to http.host: 0.0.0.0.
Is this the expected behavior with the docker setup? Or should it be set by default to this value for docker containers?

It defaults to localhost so I guess localhost cannot be exposed for some docker-networking reason.

Yes I meant if it would be better for the elastic docker beat configs to default to 0.0.0.0 instead of localhost. For server.host the default in docker is already 0.0.0.0.

Hmm, what exact files are you using? Where do you propose to apply this change?

I looked up the beats repository and couldn't find what I stated. I've read at some place in this forum that it is set for elastic docker containers by default. But sadly I cannot find the topic.
I think this topic is resolved. Thank you for your time and patience :slight_smile:

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