如何在容器中启动 cloudwatch 代理?

for*_*t17 8 amazon-ec2 amazon-cloudwatch docker

从 docker hub 有一个由亚马逊维护的图像

任何人都知道如何配置和启动容器,因为我找不到任何文档

swa*_*rov 8

我得到了这个工作!当你看到我和你有同样的问题Reading json config file path: /opt/aws/amazon-cloudwatch-agent/bin/default_linux_config.json ... Cannot access /etc/cwagentconfig: lstat /etc/cwagentconfig: no such file or directoryValid Json input schema.

您需要做的是将您的配置文件放在 /etc/cwagentconfig.conf 中。一个正常运行的 dockerfile:

FROM amazon/cloudwatch-agent:1.230621.0
COPY config.json /etc/cwagentconfig
Run Code Online (Sandbox Code Playgroud)

其中 config.json 是一些 cloudwatch 代理配置,例如 LinPy 的回答。

您可以忽略关于 的警告/opt/aws/amazon-cloudwatch-agent/bin/default_linux_config.json,或者您也可以将 config.json 文件复制到 dockerfile 中的该位置。

我还将分享我是如何找到这个答案的:

我需要在 ECS 中将此作为 sidecar 运行,而我只能找到有关如何在 Kubernetes 中运行它的文档。按照此文档:https : //docs.aws.amazon.com/en_pv/AmazonCloudWatch/latest/monitoring/Container-Insights-setup-StatsD.html 当我看到这个时,我决定下载所有示例 k8s 清单:

apiVersion: v1
kind: Pod
metadata:
  namespace: default
  name: amazonlinux
spec:
  containers:
    - name: amazonlinux
      image: amazonlinux
      command: ["/bin/sh"]
      args: ["-c", "sleep 300"]
    - name: cloudwatch-agent
      image: amazon/cloudwatch-agent
      imagePullPolicy: Always
      resources:
        limits:
          cpu:  200m
          memory: 100Mi
        requests:
          cpu: 200m
          memory: 100Mi
      volumeMounts:
        - name: cwagentconfig
          mountPath: /etc/cwagentconfig
  volumes:
    - name: cwagentconfig
      configMap:
        name: cwagentstatsdconfig
  terminationGracePeriodSeconds: 60
Run Code Online (Sandbox Code Playgroud)

所以,我看到卷装入cwagentconfig坐骑/etc/cwagentconfig,这就是从cwagentstatsdconfigconfigmap,并且只是JSON文件。