A new multi-platform CloudWatch agent is available. You can use a single agent to collect both system metrics and log files from Amazon EC2 instances and on-premises servers.
The new agent supports both Windows Server and Linux and enables you to select the metrics to be collected, including sub-resource metrics such as per-CPU core.
We recommend you use the new agent instead of the older monitoring scripts to collect metrics and logs. For more information about the CloudWatch agent, see Collect Metrics from Amazon EC2 Instances and On-Premises Servers with the CloudWatch Agent in the Amazon CloudWatch User Guide
The new agent supports both Windows Server and Linux and enables you to select the metrics to be collected, including sub-resource metrics such as per-CPU core.
We recommend you use the new agent instead of the older monitoring scripts to collect metrics and logs. For more information about the CloudWatch agent, see Collect Metrics from Amazon EC2 Instances and On-Premises Servers with the CloudWatch Agent in the Amazon CloudWatch User Guide
Package Contents
The package for the monitoring scripts contains the following files:
- CloudWatchClient.pm – Shared Perl module that simplifies calling Amazon CloudWatch from other scripts.
- mon-put-instance-data.pl – Collects system metrics on an Amazon EC2 instance (memory, swap, disk space utilization) and sends them to Amazon CloudWatch.
- mon-get-instance-stats.pl – Queries Amazon CloudWatch and displays the most recent utilization statistics for the EC2 instance on which this script is executed.
- awscreds.template – File template for AWS credentials that stores your access key ID and secret access key.
- LICENSE.txt – Text file containing the Apache 2.0 license.
- NOTICE.txt – Copyright notice.
To install the required packages
- Log on to your instance. For more information, see Connect to Your Linux Instance.
- At a command prompt, install packages as follows:
sudo yum install -y perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA.x86_64
- Also run :
sudo yum install perl-DateTime perl-CPAN perl-Net-SSLeay perl-IO-Socket-SSL perl-Digest-SHA gcc -y sudo yum install zip unzip
Getting Started
The following steps show you how to download, uncompress, and configure the CloudWatch Monitoring Scripts on an EC2 Linux instance.
To download, install, and configure the monitoring scripts
At a command prompt, move to a folder where you want to store the monitoring scripts and run the following command to download them:
curl https://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.2.zip -O
Run the following commands to install the monitoring scripts you downloaded:
unzip CloudWatchMonitoringScripts-1.2.2.zip
rm CloudWatchMonitoringScripts-1.2.2.zip
cd aws-scripts-mon
Ensure that the scripts have permission to perform CloudWatch operations using one of the following options:
-
If you associated an IAM role (instance profile) with your instance, verify that it grants permissions to perform the following operations:
-
cloudwatch:PutMetricData
-
cloudwatch:GetMetricStatistics
-
cloudwatch:ListMetrics
-
ec2:DescribeTags
Specify your AWS credentials in a credentials file.
First, copy the awscreds.template
file included with the monitoring scripts to awscreds.conf
as follows:
cp awscreds.template awscreds.conf
Add the following content to the awscreds.conf
file:
AWSAccessKeyId=my-access-key-id
AWSSecretKey=my-secret-access-key
To perform a simple test run without posting data to CloudWatch
./mon-put-instance-data.pl --mem-util --verify --verbose
To collect all available memory metrics and send them to CloudWatch
/usr/local/bin/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --disk-path=/dev/xvda1 --disk-space-util --disk-space-used --disk-space-avail
To set a cron schedule for metrics reported to CloudWatch
Start editing the crontab using the following command: crontab -e
Add the following command to report memory and disk space utilization to CloudWatch every five minutes:
*/5 * * * * /usr/local/bin/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --disk-path=/dev/xvda1 --disk-space-util --disk-space-used --disk-space-avail
After you successfully run the mon-put-instance-data.pl script, you can view your custom metrics in the Amazon CloudWatch console.
To view custom metrics
-
Run mon-put-instance-data.pl as described previously.
-
Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/.
-
Choose View Metrics.
-
For Viewing, your custom metrics posted by the script are displayed with the prefix
Comments
Post a Comment