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 grasp the system state because of the lack of complete metrics in CloudWatch. By default, CloudWatch solely supplies a couple of primary metrics similar to CPU and Networks. Nonetheless, it’s price noting that Reminiscence and Disk metrics should not included within the default metric assortment.

Fortuitously, every Elastic Beanstalk digital machine (VM) comes with a CloudWatch agent that may be simply configured to gather extra metrics. For instance, when you want details about VM reminiscence consumption, which AWS doesn’t present out of the field, you may configure the CloudWatch agent to gather this knowledge. This may tremendously improve your visibility into the efficiency and well being of your Elastic Beanstalk surroundings, permitting you to make knowledgeable choices and optimize your utility’s efficiency.

How To Configure Customized Metrics in AWS Elastic Beanstalk

To perform this, you’ll have to edit your Elastic Beanstalk zip bundle and embody a cloudwatch.config file within the .ebextensions folder on the prime of your bundle. Please notice that the configuration file ought to be chosen based mostly in your working system, as described on this article. By doing so, you’ll be capable to customise the CloudWatch agent settings and allow the gathering of extra metrics, similar to reminiscence consumption, to achieve deeper insights into your Elastic Beanstalk surroundings. This can help you successfully monitor and optimize the efficiency of your utility on AWS.

recordsdata:
  "/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: /decide/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/decide/aws/amazon-cloudwatch-agent/bin/config.json
recordsdata:
  "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 will have seen, I enabled just a few memory-related metrics similar to mem_total, mem_available, mem_used, mem_free, and mem_used_percent. Nonetheless, you may allow extra metrics as wanted. The entire record of obtainable metrics could be discovered right here.

After getting up to date your utility, 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 may create a widget by clicking the Add widget button and deciding on Line to create a line chart that shows the specified metrics. Customizing a dashboard with related metrics can present priceless insights into the efficiency and well being of your Elastic Beanstalk surroundings, making it simpler to observe and optimize your utility 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.

Closing Ideas

Be happy to discover the wide range of metrics and AWS widgets out there in CloudWatch to additional customise your dashboard. When you’ve got any questions or want help, be at liberty 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