How to monitor docker containers log from non-root user?
Asked Answered
H

4

6

I want to monitor docker containers log from non-root user(td-agent) and on host server,

sudo chmod o+rx /var/lib/docker
sudo find /var/lib/docker/containers/ -type d -exec chmod o+rx {} \;
sudo find /var/lib/docker/containers/ -type f -exec chmod o+r {} \;

But containers directory rollback 600 and each container directory keep 600.

# find /var/lib/docker/containers -ls
143142    4 drwx------   4 root     root         4096 Aug 14 12:01 /var/lib/docker/containers
146027    4 drwx------   2 root     root         4096 Aug 14 12:00 /var/lib/docker/containers/145efa73652aad14e1706e8fcd1597ccbbb49fd756047f3931270b46fe01945d
146031    4 -rw-r--r--   1 root     root          190 Aug 14 12:00 /var/lib/docker/containers/145efa73652aad14e1706e8fcd1597ccbbb49fd756047f3931270b46fe01945d/hostconfig.json
146046    4 -rw-r--r--   1 root     root           13 Aug 14 12:00 /var/lib/docker/containers/145efa73652aad14e1706e8fcd1597ccbbb49fd756047f3931270b46fe01945d/hostname
146047    4 -rw-r--r--   1 root     root          174 Aug 14 12:00 /var/lib/docker/containers/145efa73652aad14e1706e8fcd1597ccbbb49fd756047f3931270b46fe01945d/hosts
146030    4 -rw-r--r--   1 root     root         3305 Aug 14 12:00 /var/lib/docker/containers/145efa73652aad14e1706e8fcd1597ccbbb49fd756047f3931270b46fe01945d/config.json
146049    4 -rw-------   1 root     root         1853 Aug 14 12:00 /var/lib/docker/containers/145efa73652aad14e1706e8fcd1597ccbbb49fd756047f3931270b46fe01945d/145efa73652aad14e1706e8fcd1597ccbbb49fd756047f3931270b46fe01945d-json.log
146050    4 drwx------   2 root     root         4096 Aug 14 12:01 /var/lib/docker/containers/f09796f978ef5bab1449d2d10d400228eb76376579e7e33c615313eeed53f370
146054    4 -rw-r--r--   1 root     root          190 Aug 14 12:01 /var/lib/docker/containers/f09796f978ef5bab1449d2d10d400228eb76376579e7e33c615313eeed53f370/hostconfig.json
146056    4 -rw-r--r--   1 root     root           13 Aug 14 12:01 /var/lib/docker/containers/f09796f978ef5bab1449d2d10d400228eb76376579e7e33c615313eeed53f370/hostname
146057    4 -rw-r--r--   1 root     root          174 Aug 14 12:01 /var/lib/docker/containers/f09796f978ef5bab1449d2d10d400228eb76376579e7e33c615313eeed53f370/hosts
146053    4 -rw-r--r--   1 root     root         3286 Aug 14 12:01 /var/lib/docker/containers/f09796f978ef5bab1449d2d10d400228eb76376579e7e33c615313eeed53f370/config.json
146058    4 -rw-------   1 root     root         1843 Aug 14 12:01 /var/lib/docker/containers/f09796f978ef5bab1449d2d10d400228eb76376579e7e33c615313eeed53f370/f09796f978ef5bab1449d2d10d400228eb76376579e7e33c615313eeed53f370-json.log

How to monitor this each json.log? or any other good monitoring way?

H answered 14/8, 2014 at 16:10 Comment(0)
P
7

logspout is another way to collect containerslogs. I'm not sure this is the best solution, but it is very interesting and consistent way to collect containers logs.

You just need to run logspout container. This container has a feature that send docker containers' logs to other syslog server. (or you can use HTTP api also. see repository)

# (172.17.42.1 is host ip address)
$ docker run -v=/var/run/docker.sock:/tmp/docker.sock progrium/logspout syslog://172.17.42.1:5140

And fluentd that is running on host can handle these logs through syslog protocal. Below is td-agent.conf example. It receive logs from syslog protocal and send them to elasticsearch server. (check this example project)

<source>
  type syslog
  port 5140
  bind 0.0.0.0
  tag syslog.udp
  format /^(?<time>.*?) (?<container_id>.*?) (?<container_name>.*?): (?<message>.*?)$/
  time_format %Y-%m-%dT%H:%M:%S%z
</source>

<match syslog.**>
  index_name <ES_INDEX_NAME>
  type_name <ES_TYPE_NAME>
  type elasticsearch
  host <ES_HOST>
  port <ES_PORT>
  flush_interval 3s
</match>
Polycarp answered 14/8, 2014 at 18:14 Comment(2)
I choose this solution!H
This approch is somewhat risky because Docker have a memory leak problem related with log(github.com/docker/docker/issues/9139). This problem will be fixed when Docker 1.5.1 released(github.com/docker/docker/pull/10347).Polycarp
M
1

As I discussed in detail in this answer that the OP never acknowledged whatsoever, I find the best approach is to configure the applications running within the container to log messages to syslog, and mount the host's syslog socket to the container.

docker run -v /dev/log:/dev/log ...

Downside of this approach is that if the syslog daemon on the host is restarted, the container will lose it's socket since the daemon recreates the socket at restart.

A fix for this would be to add another socket (in rsyslog this can be done using the imuxsock module). Create the additional socket in some known directory, then bind mount the directory instead of /dev/log directly. The additional socket will also be removed when rsyslog restarts, but will be recreated and available to the application in the directory following the restart.

Mayorga answered 14/8, 2014 at 21:52 Comment(0)
R
1

One easy way to deal with this issue is to mount host's /sys/fs/cgroup into a Docker container that's running in_docker_metrics. See https://github.com/bdehamer/docker-librato

Reiche answered 3/9, 2014 at 0:21 Comment(0)
P
0

Sematext Docker Agent (open-source, github) can do this for you. You won't need td-agent. SDA will collect logs, but also events and metrics. See https://github.com/sematext/sematext-agent-docker and https://sematext.com/docker

Pedersen answered 5/8, 2016 at 4:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.