How to start the cloudwatch agent in container?

后端 未结 5 1576
轮回少年
轮回少年 2021-02-09 02:54

From the docker hub there is an image which is maintained by amazon.

Any one know how to configure and start the container as I cannot find any documen

5条回答
  •  无人共我
    2021-02-09 03:30

    I got this working! I was having the same issue with you when you see 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.

    What you need to do is put your config file in /etc/cwagentconfig. A functioning dockerfile:

    FROM amazon/cloudwatch-agent:1.230621.0
    COPY config.json /etc/cwagentconfig
    

    Where config.json is some cloudwatch agent configuration, such as given by LinPy's answer.

    You can ignore the warning about /opt/aws/amazon-cloudwatch-agent/bin/default_linux_config.json, or you can also COPY the config.json file to that location in the dockerfile as well.

    I will also share how I found this answer:

    I needed this run in ECS as a sidecar, and I could only find docs on how to run it in kubernetes. Following this documentation: https://docs.aws.amazon.com/en_pv/AmazonCloudWatch/latest/monitoring/Container-Insights-setup-StatsD.html I decided to download all the example k8s manifests, when I saw this one:

    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
    

    So I saw that the volume mount cwagentconfig mounts to /etc/cwagentconfig and that's from the cwagentstatsdconfig configmap, and that's just the json file.

提交回复
热议问题