如何从我的 Deis apps/containers 获取更精确的日志源?

How can I get more precise log sources from my Deis apps/containers?

我有一个 Deis cluster running in a (hopefully-soon-to-be) Production environment, with quite a few different apps using the Dockerfile deployment method. Everything's running fine, but promoting this system to a true Production environment (that is, converting the DNS over) isn't really possible unless I can get some worthwhile log output. Using the standard Deis logging platform,这是 Web 命中的一些示例输出(对于上下文,输出更多):

Feb 10 01:46:04 ip-10-21-2-154.ec2.internal systemd[1]: Starting Generate /run/coreos/motd...
Feb 10 01:46:04 ip-10-21-2-154.ec2.internal systemd[1]: Started Generate /run/coreos/motd.
Feb 10 01:46:08 ip-10-21-2-154.ec2.internal docker[1867]: [info] GET /containers/json
Feb 10 01:46:08 ip-10-21-2-154.ec2.internal docker[1867]: [215084df] +job containers()
Feb 10 01:46:08 ip-10-21-2-154.ec2.internal docker[1867]: [215084df] -job containers() = OK (0)
Feb 10 01:46:09 ip-10-21-2-154.ec2.internal sh[1316]: 2015/02/10 01:46:09 set /deis/services/production-web/production-web_v8.cmd.1 -> 10.21.2.154:49409
Feb 10 01:46:12 ip-10-21-2-154.ec2.internal sh[9844]: 2015-02-10 01:46:12.302721 7f213ae14700  0 mon.ip-10-21-2-154.ec2.internal@4(peon).data_health(58) update_stats avail 80% total 102400 MB, used 17621 MB, avail 82542 MB
Feb 10 01:46:18 ip-10-21-2-154.ec2.internal docker[1867]: [info] GET /containers/json
Feb 10 01:46:18 ip-10-21-2-154.ec2.internal docker[1867]: [215084df] +job containers()
Feb 10 01:46:18 ip-10-21-2-154.ec2.internal docker[1867]: [215084df] -job containers() = OK (0)
Feb 10 01:46:19 ip-10-23-1-151.ec2.internal sh[1521]: [INFO] - [10/Feb/2015:01:46:27 +0000] - 10.21.2.179 - - - 200 - "GET / HTTP/1.1" - 4927 - "-" - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36" - "~^production-web\x5C.(?<domain>.+)$" - 10.21.2.154:49409
Feb 10 01:46:19 ip-10-21-2-154.ec2.internal sh[8468]: ===========
Feb 10 01:46:19 ip-10-21-2-154.ec2.internal sh[8468]: HIT TRACKER
Feb 10 01:46:19 ip-10-21-2-154.ec2.internal sh[8468]: SLUG: public/javascripts/bundle.js
Feb 10 01:46:19 ip-10-21-2-154.ec2.internal sh[8468]: ===========

其中包含 很多 的平台信息 – 拥有这些信息真是太好了,要是我能过滤掉它就好了。问题是源为 sh 但具有不同 PID 的所有行。这些都是完全不同的容器:

我找到答案的唯一方法是通过 ssh 进入盒子并 运行 ps。更糟糕的是,如果我同时有来自其他容器的任何日志,它们将 also 显示为 sh – 在具有多个活动应用程序的生产环境中所有日志记录以同流,这种情况显然是站不住脚的。理想情况下 sh 将替换为 Docker 容器的名称,或者最好是 Deis 应用程序的名称。

我查阅了文档并深入研究了 logspout and logger 源代码,但找不到任何解决方法。我有机会在这里得到一些指示吗?

为了获取记录该行的 deis 容器的名称,我发现的最佳方法是:

  1. 到 运行 journalctl -f -o short 的输出通过 netcat 到 fluentd 或 logstash tcp 侦听器。您可以使用这些工具来总结像 _SYSTEMD_UNIT 这样符合您需求的字段。
  2. 使用 ianblenke/fluentd with LOG_DOCKER_JSON defined or fork and modify the autobuild source docker-ianblenke/fluentd. This uses the fluentd-docker 插件来跟踪原始 docker 容器 json 日志。

如果您使用的是 CoreOS,我会使用此 fluentd.cloud-init 将我的日志自动传送到 TCP 9200 上的本地 elasticsearch 实例。也会在该项目中找到其他有用的 CoreOS cloud-init 配置.