【问题标题】:DataDog docker agent doesn't recieve logs from application containerDataDog docker agent 不接收来自应用程序容器的日志
【发布时间】:2019-07-31 21:49:10
【问题描述】:

我有 Golang 应用程序,它使用 Logrus 将日志写入标准输出。 我试图重新创建这个https://github.com/DataDog/docker-compose-example 场景,并用我的应用程序替换 python 应用程序。 但日志不会进入 Datadog 仪表板 这是 docker-compose 我正在努力工作

version: "3"
services:
  gos:
    build: goapp
    stdin_open: true
    ports:
      - "6000:6000"
    volumes:
      - /tmp/goapp:/tmp/goapp
      - ./goapp:/code
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - DATADOG_HOST=datadog
  web:
    build: web
    command: python app.py
    ports:
     - "5000:5000"
    volumes:
     - ./web:/code # modified here to take into account the new app path
    links:
     - redis
    environment:
     - DATADOG_HOST=datadog # used by the web app to initialize the Datadog library
  redis:
    image: redis
  # agent section
  datadog:
    build: datadog
    links:
     - redis # ensures that redis is a host that the container can find
     - web # ensures that the web app can send metrics
    environment:
     - DD_API_KEY=34f-------63c
    volumes:
     - /var/run/docker.sock:/var/run/docker.sock
     - /proc/:/host/proc/:ro
     - /sys/fs/cgroup:/host/sys/fs/cgroup:ro

我还尝试通过https://docs.datadoghq.com/logs/log_collection/docker/?tab=containerinstallation 说明为代理安装非撰写但简单的 docker 容器。

我运行我的 golang 应用程序容器

docker run -v /var/run/docker.sock:/var/run/docker.sock:rw -d testgo

使用 Dockerfile

FROM golang:1.7.3
WORKDIR /go/src/github.com/alexellis/href-counter/
RUN go get -d -v github.com/Sirupsen/logrus
COPY app.go .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app .

FROM alpine:latest  
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=0 /go/src/github.com/alexellis/href-counter/app .
EXPOSE 6000
LABEL "com.datadoghq.ad.logs"='[{"source": "goapp", "service": "webapp"}]'
CMD ["./app"] 

DD 代理可以看到应用容器的起伏,但没有收到任何日志

【问题讨论】:

  • 您是否在代理上启用了日志收集?请参阅此处示例中使用的环境变量。 docs.datadoghq.com/logs/log_collection/docker/…
  • 是的,我做到了,我已经更新了原帖
  • 你确定吗?看起来您在原始帖子或任何地方的任何地方都没有 DD_LOGS_ENABLED=true 变量...

标签: docker docker-compose datadog


【解决方案1】:

在我看来,您的 docker-compose datadog 服务配置中缺少几个环境变量。还有添加注册表以从 docker 套接字跟踪日志的卷。如果你还没有,不妨试试这样的方法?

  # agent section
  datadog:
    build: datadog
    links:
     - redis # ensures that redis is a host that the container can find
     - web # ensures that the web app can send metrics
    environment:
     - DD_API_KEY=34f-------63c
     - DD_LOGS_ENABLED=true
     - DD_LOGS_CONFIG_CONTAINER_COLLECT_ALL=true
     - DD_AC_EXCLUDE="name:datadog-agent"
    volumes:
     - /var/run/docker.sock:/var/run/docker.sock:ro
     - /proc/:/host/proc/:ro
     - /sys/fs/cgroup/:/host/sys/fs/cgroup:ro
     - /opt/datadog-agent/run:/opt/datadog-agent/run:rw

从那里开始,如果您仍然遇到问题,您可能需要联系 support@datadoghq.com 寻求帮助。他们很快就回复了。

【讨论】:

    猜你喜欢
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 2019-08-21
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    • 2018-09-18
    • 2019-10-24
    相关资源
    最近更新 更多