Reputation: 340
I want to monitor memory used by particular process under cloudwatch
in AWS
. Do I have to use script to do so? If yes, let me know the steps or some guideline or Can I use cloudwatch logs
to report memory utilized by particular process in real time? Tell me the other alternatives as well.
Upvotes: 14
Views: 10301
Reputation: 57
You can try AWS CloudWatch procstat plugin. Apart from memory using memory_data
param of procstat, you can monitor many other data of process. I have answered here.
A sample JSON configuration file using procstat -
{
"agent":{
"metrics_collection_interval":60,
"region":"us-south-1",
"logfile":"/opt/aws/amazon-cloudwatch-agent/logs/process-monitoring.log"
},
"metrics":{
"namespace":"CWAgent",
"append_dimensions":{
"AutoScalingGroupName":"${aws:AutoScalingGroupName}"
},
"aggregation_dimensions":[
[
"AutoScalingGroupName"
]
],
"force_flush_interval":60,
"metrics_collected":{
"procstat":[
{
"pid_file":"/var/opt/data/myapp/tmp/sampleApp.pid",
"measurement":[
"memory_data",
"memory_locked",
"memory_rss"
],
"metrics_collection_interval":30
}
]
}
}
}
Upvotes: 0
Reputation: 3503
While the reason provided by @EJBrennan in his answer is correct, a more recent update to this question is to simply install the scripts as provided in this excellent documentation from AWS
AWS Documentation for Memory & Disk Metrics
So you need to
./mon-put-instance-data.pl --mem-util --mem-used-incl-cache-buff --mem-used --mem-avail
Alternatively, you can also setup a cron job to get the metrics on a periodic basis.
Hope that helps
Upvotes: 0
Reputation: 1222
Put this in a file called 001initial.config in your .ebextensions folder of your s3 bucket you're using for your app ver. This will install the monitoring and set it up as a cron job. Note the perl modules that get installed. You'll want to ssh into your box and test the script is running.
Go into security and update your iam role for you ec2 instance with CloudWatch rights. Make sure to select the checkbox for the role and then click it to get to the rights page.
Once you know monitoring is running, go to the cloud watch page, and from the very first page type in System/Linux and search for that and it will show you disk and memory stats.
---
files:
"/etc/cron.d/my_cron":
mode: "000644"
owner: root
group: root
content: |
# run a cloudwatch command every five minutes (as ec2-user)
*/5 * * * * ec2-user ~/aws-scripts-mon/mon-put-instance-data.pl --mem-util --mem-used --mem-avail --disk-space-util --disk-path=/ --from-cron
encoding: plain
commands:
# delete backup file created by Elastic Beanstalk
clear_cron_backup:
command: rm -f /etc/cron.d/watson.bak
container_commands:
02download:
command: "curl http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip -O"
ignoreErrors: true
03extract:
command: "unzip CloudWatchMonitoringScripts-1.2.1.zip"
ignoreErrors: true
04rmzip:
command: "rm rm CloudWatchMonitoringScripts-1.2.1.zip"
ignoreErrors: true
05cdinto:
command: "mv aws-scripts-mon/ /home/ec2-user"
ignoreErrors: true
packages:
yum:
perl-Switch : []
perl-URI: []
perl-Bundle-LWP: []
perl-DateTime: []
perl-Sys-Syslog: []
perl-LWP-Protocol-https: []
Upvotes: 1
Reputation: 46841
Yes, you will need a script that runs on the instance you want to monitor. Cloudwatch by default can only report on things it can 'see' at the hypervisor level, not things that re going on 'inside', so you'll need to create and report 'custom metrics'.
Here are some Linux script pointers: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/mon-scripts.html
and some for windows: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/mon-scripts-powershell.html
Upvotes: 11