0

I'm trying to use CloudWatch embedded metrics format (emf) inside a beanstalk environment running Docker image.

(Documentation on emf here and here )

To be able to emit emf metrics, the aws-cloudwatch-agent needs to have the following configuration:

{
  "logs": {
    "metrics_collected": {
      "emf": { }
    }
  }
}

However I'm not able to find the namespace definition to pass emf configuration to beanstalk, using the .ebextensions method described here. The available namespaces seem to just stream the existing logs.

How can I enable CloudWatch emf publishing in an elastic beanstalk environment?

mikethe
  • 147
  • 1
  • 2
  • 14
  • Not sure if this what you are looking for. But here you go - https://stackoverflow.com/questions/62123153/logging-custom-metrics-using-aws-cloudwatch-agent-and-python – gowthz Nov 27 '21 at 02:20
  • @GowthamBhat - Thanks, it was not exactly the answer but pointed in the right direction. – mikethe Dec 02 '21 at 14:18

1 Answers1

0

To pass additional configuration use platform hooks described in this question. More detail on platform hooks: AWS documentation,

  1. I've included .platform/hooks/predeploy/emf-config.sh with content:
#!/bin/bash

echo '{
        "logs": {
          "metrics_collected": {
            "emf": { }
          }
        }
      }' > "/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/emf_metrics.json"
/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a append-config
  1. If you use docker, make sure to include this files in your docker image. Using CDK pipeline I've included:
    (...)
    artifacts: {
        files: [
            "Dockerrun.aws.json",
            ".platform/hooks/**/*"
        ]
    },
  1. Finally, make sure to add execution permissions to the .sh file. Related question
chmod +x path/to/emf-config.sh
git update-index --chmod=+x path/to/emf-config.sh
mikethe
  • 147
  • 1
  • 2
  • 14