One of the best thing about AWS is that it can able to meet any prominent need of IT requirements. Also AWS another prominent feature is that it will enable us to create custom alarm for monitoring memory utilization and disk space usage but it cannot be activated unless we do it by ourself. So, let’s look on how to set up Amazon CloudWatch: Memory Monitoring & Disk Metrics In Amazon EC2 Ubuntu Instances.
Amazon CloudWatch is providing a reliable, scalable, and flexible monitoring solution that you can start using within minutes. You no longer need to set up, manage or scale your own monitoring servers. In addition, it allows you to collect custom metrics from your own applications to monitor operational performance, troubleshoot issues, and to spot the current trends. All the same CloudWatch functionality will be available up to one second frequency for your own custom metrics data, including statistics, graphs, and alarms.
Before installing the monitoring scripts, we should install the dependent packages on Ubuntu.
Now, Log in to your server instance. And from the command prompt, install the packages using the following steps:
sudo apt-get update
sudo apt-get install unzip
sudo apt-get install libwww-perl libdatetime-perl
How To Install The Monitoring Scripts:
By following these steps you can download, unzip and configure the CloudWatch Monitoring scripts on ubuntu server.
1. In command prompt, change the directory to where you want to locate the monitoring scripts.
2. Run the following command to download source:
curl https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.2.zip -O
2. Uncompress the downloaded source using following command:
unzip CloudWatchMonitoringScripts-1.2.2.zip && \
rm CloudWatchMonitoringScripts-1.2.2.zip && \
The retrieved directory will have a list of Perl scripts. These scripts will report memory and disk space utilization metrics for an Ubuntu server.
The directory contains the following listed files:
CloudWatchClient.pm – This file module will simplify calling Amazon Cloud Watch using from other scripts.
mon-put-instance-data.pl – This file will collect system metrics on ubuntu server and sends them to Amazon Cloud Watch.
mon-get-instance-stats.pl – This file will display the recent utilization statistics reports for the instance on which this script was executed.
awscreds.template – This file will have an example of AWS credentials keys named with access key ID and secret access key.
LICENSE.txt – This file contains the Apache 2.0 license.
NOTICE.txt – This file contains a Copyright notice.
3. To do the Cloud Watch operations, Confirm that whether the scripts have permission to perform actions:
If you associated an IAM role with your EC2 Ubuntu instance, verify that it grants permissions to perform the listed operations:
You can update the AWS credentials by copying the ‘awscreds.template’ file into ‘awscreds.conf’ using below command and just update the file AWS credentials,
cp awscreds.template awscreds.conf
This are the keys which are available under that file you can use it to update credentials.
Now the configuration was done.
Simple Test Run Without Sending Data To CloudWatch
This file script collects memory, swap, and disk space utilization data on the current system and it makes a remote call to Amazon Cloud Watch to report the collected cloud watch data as custom metrics.
./mon-put-instance-data.pl --mem-util --verify --verbose
Set A Cron Schedule For Metrics And Send Them To AWS CloudWatch
1. Edit the crontab using below the following command:
2. Update the file with the following query to report memory and disk space utilization, this will report the particular paths to CloudWatch every five minutes:
*/5 * * * * ~/STORAGE/cloudwatch/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-avail --mem-used --disk-space-util --disk-space-avail --disk-space-used --disk-path=/ --disk-path=/STORAGE --from-cron
If any error occurs, the script will write the error messages in the system log.
I have used too many options in the above command. If you’re too confused to use this then let me explain you the uses of all the options in brief.
This will collect the memory utilization information in percentage and will send to the MemoryUtilization metrics. Also, it will count memory of usage applications and the OS.
This will collect the used memory and will send the reports in megabytes to the MemoryUsed metrics. This metric counts memory allocated by applications and the OS as used.
This will collect the available memory and sends the reports in megabytes to the MemoryAvailable metrics. This metric counts memory allocated by applications and the OS as used.
This will collect the utilized disk space and sends the reports in percentage to the DiskSpaceUtilization metric for the selected disks.
This will collect the used disk space and sends the reports in gigabytes to the DiskSpaceUsed metric for the selected disks.
This will collect the available disk space and sends the reports in gigabytes to the DiskSpaceAvailable metric for the selected disks.
This will point out the path on which path the disk space report need to be addressed. Alongside, the PATH will specify the mount point or any file located on a mount point on where the filesystem needs to be reported.
If you want to point the multiple disks then you can specify the both disks like below:
Set The Alarm For Custom Metrics
Basically, if we try to create alarm for metrics then it will list only the default metrics and it will not include custom metrics. So, before running the Perl Scripts, Here are some default metrics am listing it for your reference.
Once we set the cron, the custom metrics will be located in Linux System Metrics.
Also Don’t Miss Out: Implementing Single Sign In For Multiple Application Using JanRain
Create Alarm For Custom Metrics
1) Open the cloudwatch console panel at https://console.aws.amazon.com/cloudwatch/home
2) In the navigation pane, click on Alarm and Create Alarm.
3) It will open a popup with the list of CloudWatch metrics by category.
4) Click on Linux System Metrics.
5) It will list out with custom metrics like below pictures
6) Select a metric and click on Next button. Now it navigates to the section where you can Define Alarm section.
7) Define the Alarm with required fields.
- Enter the Alarm name for identification.
- Give the description of the alarm.
- Give the condition with the maximum limit of percentage or bytes count(based on metrics report format, for example, 80 percent of MemoryUtilization) for when it has to raise the alarm. If it satisfies the condition, it will trigger the alarm.
- Provide additional information for your alarm.
- Define what actions are taken when your alarm changes state.
- Select or create a topic with listed emails for sending notification about alarm state.
Best To Read: 12 Best Golang Practices We Must Follow
8) Finally, choose to Create Alarm.
That’s it. Now the alarm will be created for selected custom metrics.
Now the alarm we set will list out under the selected state. Based on the selected state it will send notification to the listed emails but note to yourself that it will send the notifications only when the condition is satisfied as we already state that it should not reach the maximum limit either for the percentage or the bytes count. Finally, we can able to see the history of alarm and it’s details by clicking the alarm from the list.
Want to learn more? Then never miss out anything from our largest blog portal where you can get continuous blog updates & latest posts about all latest technologies which would be perfect for your 15 minutes tea break! In case if you’re a newbie then don’t forget to subscribe us to get the latest updates from diverse technologies. What else guys hit the subscribe link and go crazy over learning. For more inquires reach us via email@example.com