Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start the cloudwatch agent in container?

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 documentation

like image 688
forum.test17 Avatar asked Sep 27 '19 12:09

forum.test17


People also ask

How do I start CloudWatch agent on Windows?

Starting the CloudWatch Agent Inside of your open PowerShell console, change into the CloudWatch directory by running cd "C:Program FilesAmazonAmazonCloudWatchAgent" and then run the command below to start the CloudWatch agent with the config file you just created on an EC2 instance.


1 Answers

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.

like image 65
swagrov Avatar answered Oct 10 '22 00:10

swagrov