Configure Customized Metrics in AWS Elastic Beanstalk – DZone – Uplaza

Not too long ago, I encountered a activity the place a enterprise was utilizing AWS Elastic Beanstalk however was struggling to know the system state as a result of lack of complete metrics in CloudWatch. By default, CloudWatch solely supplies just a few primary metrics reminiscent of CPU and Networks. Nevertheless, it’s value noting that Reminiscence and Disk metrics usually are not included within the default metric assortment.

Happily, every Elastic Beanstalk digital machine (VM) comes with a CloudWatch agent that may be simply configured to gather further metrics. For instance, when you want details about VM reminiscence consumption, which AWS doesn’t present out of the field, you’ll be able to configure the CloudWatch agent to gather this information. This could drastically improve your visibility into the efficiency and well being of your Elastic Beanstalk surroundings, permitting you to make knowledgeable selections and optimize your software’s efficiency.

How To Configure Customized Metrics in AWS Elastic Beanstalk

To perform this, you’ll must edit your Elastic Beanstalk zip bundle and embody a cloudwatch.config file within the .ebextensions folder on the high of your bundle. Please notice that the configuration file must be chosen based mostly in your working system, as described on this article. By doing so, you’ll be capable of customise the CloudWatch agent settings and allow the gathering of further metrics, reminiscent of reminiscence consumption, to realize deeper insights into your Elastic Beanstalk surroundings. It will mean you can successfully monitor and optimize the efficiency of your software on AWS.

information:
  "/opt/aws/amazon-cloudwatch-agent/bin/config.json":
    mode: "000600"
    proprietor: root
    group: root
    content material: |
      {
        "agent": {
          "metrics_collection_interval": 60,
          "run_as_user": "root"
        },
        "metrics": {
          "append_dimensions": {
            "InstanceId": "$${aws:InstanceId}"
          },
          "metrics_collected": {
            "mem": {
              "measurement": [
                "mem_total",
                "mem_available",
                "mem_used",
                "mem_free",
                "mem_used_percent"
              ]
            }
          }
        }
      }
container_commands:
  apply_config_metrics:
    command: /choose/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/choose/aws/amazon-cloudwatch-agent/bin/config.json
information:
  "C:Program FilesAmazonAmazonCloudWatchAgentcw-memory-config.json":
    content material: |
{
        "agent": {
          "metrics_collection_interval": 60,
          "run_as_user": "root"
        },
        "metrics": {
          "append_dimensions": {
            "InstanceId": "$${aws:InstanceId}"
          },
          "metrics_collected": {
            "mem": {
              "measurement": [
                "mem_total",
                "mem_available",
                "mem_used",
                "mem_free",
                "mem_used_percent"
              ]
            }
          }
        }
      }

container_commands:
  01_set_config_and_reinitialize_cw_agent:
    command: powershell.exe cd 'C:Program FilesAmazonAmazonCloudWatchAgent'; powershell.exe -ExecutionPolicy Bypass -File ./amazon-cloudwatch-agent-ctl.ps1 -a append-config -m ec2 -c file:cw-memory-config.json -s; powershell.exe -ExecutionPolicy Bypass -File ./amazon-cloudwatch-agent-ctl.ps1 -a begin; exit

As you might have seen, I enabled only some memory-related metrics reminiscent of mem_total, mem_available, mem_used, mem_free, and mem_used_percent. Nevertheless, you’ll be able to allow extra metrics as wanted. The whole checklist of obtainable metrics may be discovered right here.

Upon getting up to date your software, it will be useful to create a CloudWatch dashboard to visualise these metrics. To take action, navigate to the AWS CloudWatch console, choose Dashboards, and click on on Create dashboard. From there, you’ll be able to create a widget by clicking the Add widget button and choosing Line to create a line chart that shows the specified metrics. Customizing a dashboard with related metrics can present invaluable insights into the efficiency and well being of your Elastic Beanstalk surroundings, making it simpler to observe and optimize your software on AWS.

Within the case of the instance above, we’ll see 5 new metrics within the part CWAgent.

Based mostly on them, we might configure a reminiscence widget and get one thing like this.

Last Ideas

Be happy to discover the big variety of metrics and AWS widgets obtainable in CloudWatch to additional customise your dashboard. When you have any questions or want help, be happy to ask me within the feedback.

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version