docker-filebeat icon indicating copy to clipboard operation
docker-filebeat copied to clipboard

Any way to filter what containers get logged?

Open Ryuzavi opened this issue 8 years ago • 4 comments

Hey

Got this working with separate images for ELK. Notice that the filebeat container obviously picks up all the containers (including itself!).

Is there anyway to filter what containers filebeat picks up?

Cheers, R.

Ryuzavi avatar Jul 06 '16 15:07 Ryuzavi

I'm testing out an implementation of this using container labels, i.e. only process containers that have a specific key / value in the labels. Have a look at my fork for details: https://github.com/gdubya/docker-filebeat

UPDATE: Sorry, no longer maintaining the fork, however the changes are contained in a gist: https://gist.github.com/gdubya/23b3fc0ff58084d3df85fe8a798ff2f5

gdubya avatar Dec 28 '16 23:12 gdubya

I took a slightly different approach where it defaults to a label, but has teh option to choose your own label or use all.

Full source at: https://github.com/willfarrell/docker-filebeat/blob/master/5-stdin/docker-entrypoint.sh

# Set container selector
  if [ "$STDIN_CONTAINER_LABEL" == "all" ]; then
    selector() {
      jq -r .[].Id
    }
  else
    selector() {
      jq -r '.[] | select(.Labels["'${STDIN_CONTAINER_LABEL:=filebeat.stdin}'"] == "true") | .Id'
    }
  fi

while true; do
    CONTAINERS=$(curl --no-buffer -s -XGET --unix-socket ${DOCKER_SOCK} http://localhost/containers/json | selector)
    ...
    sleep 5
  done

willfarrell avatar Feb 03 '17 01:02 willfarrell

@gdubya Looks like you took down your fork, would you mind republishing it somewhere or sharing your solution? Thanks!

yayitswei avatar Oct 16 '17 03:10 yayitswei

Ah, sorry, I deleted the fork. But here's a gist containing the changes that I made to Dockerfile and the entrypoint script: https://gist.github.com/gdubya/23b3fc0ff58084d3df85fe8a798ff2f5

gdubya avatar Oct 16 '17 10:10 gdubya