{"id":11349,"date":"2014-01-17T17:25:53","date_gmt":"2014-01-17T11:55:53","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=11349"},"modified":"2015-07-09T15:36:42","modified_gmt":"2015-07-09T10:06:42","slug":"setup-custom-cloudwatch-metrics-on-ec2-instance","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/setup-custom-cloudwatch-metrics-on-ec2-instance\/","title":{"rendered":"Setup custom CloudWatch metrics on EC2 instance"},"content":{"rendered":"<p>AWS provides its user the <a title=\"AWS Monitoring Services\" href=\"http:\/\/www.tothenew.com\/devops-aws\">Cloud Monitoring service which is used<\/a> to keep a check on the resources being used.<\/p>\n<p dir=\"ltr\">It can be a great tool for <a title=\"AWS Developers and Administrators\" href=\"http:\/\/www.tothenew.com\/wcm\/cq-aem-development-consulting\">developers and system administrators<\/a> for cases like:<\/p>\n<ul>\n<li><span style=\"color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, 'Nimbus Sans L', sans-serif; font-style: normal;\">Monitoring data\/graphs<\/span><\/li>\n<li><span style=\"color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, 'Nimbus Sans L', sans-serif; font-style: normal;\">Setting up alarms<\/span><\/li>\n<li><span style=\"color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, 'Nimbus Sans L', sans-serif; font-style: normal;\">Identify trends<\/span><\/li>\n<li><span style=\"color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, 'Nimbus Sans L', sans-serif; font-style: normal;\">Take actions based on the state of cloud environment<\/span><\/li>\n<\/ul>\n<p>But AWS does not provide the memory and the disk utilization metrics out of the box.These metrics can be monitored using third party scripts that are are written in Perl and are verified by AWS.<\/p>\n<p>To install the scripts a few very basic and simple steps need to be followed, which are:<\/p>\n<p><strong>Prerequisites: \u00a0<\/strong><\/p>\n<p dir=\"ltr\">We\u2019ll have to install the following packages to get these scripts to work.<\/p>\n<ol>\n<li>\n<p dir=\"ltr\">For Debian Flavored Servers,<\/p>\n<p>[shell]sudo apt-get install unzip libwww-perl libcrypt-ssleay-perl[\/shell]<\/p>\n<\/li>\n<\/ol>\n<ol>\n<li>\n<p dir=\"ltr\">For Red Hat Flavored Servers,<\/p>\n<p>[shell]cd \/<br \/>\nyum install perl-Digest-SHA1<br \/>\nperl -MCPAN -e shell ## Type &#8216;yes&#8217; at every prompt, this will drop you at cpan prompt.<br \/>\ncpan[1]&gt; install Bundle::LWP5_837 LWP ## Here also type &#8216;yes&#8217; at every prompt.[\/shell]<\/p>\n<\/li>\n<\/ol>\n<p dir=\"ltr\">Now we will download and configure the CloudWatch Monitoring Scripts on EC2 Linux system.<\/p>\n<p dir=\"ltr\">Following are the steps which we need to follow:<\/p>\n<p>[shell]cd \/opt<br \/>\nwget http:\/\/ec2-downloads.s3.amazonaws.com\/cloudwatch-samples\/CloudWatchMonitoringScripts-v1.1.0.zip<br \/>\nunzip CloudWatchMonitoringScripts-v1.1.0.zip<br \/>\nrm CloudWatchMonitoringScripts-v1.1.0.zip<br \/>\ncd aws-scripts-mon<br \/>\nopen the\u00a0awscreds.template\u00a0file and enter your accesskeyid and secret key[\/shell]<\/p>\n<p>Above mentioned commands will set up the the required monitoring for us. Next step for us would be to send memory and disk usage details to CloudWatch, which would enable us to access information and setup alarms from AWS CloudWatch console.<\/p>\n<p>The command below runs every minute and pushes data to CloudWatch. And to enable 1 minute granularity in CloudWatch we would also need to enable \u201cDetailed Monitoring\u201d.<\/p>\n<p>[shell]*\/1 * * * * \/opt\/aws-scripts-mon\/mon-put-instance-data.pl &#8211;mem-util &#8211;disk-space-util \u00a0&#8211;swap-util &#8211;disk-path=\/ &#8211;disk-path=\/data &#8211;aws-credential-file=\/opt\/mon-scripts\/awscreds.template[\/shell]<\/p>\n<p dir=\"ltr\">In the above command we are monitoring two EBS volumes, one is Root volume and another volume which we have mounted on \/data directory. It will push data every minute to CloudWatch.<\/p>\n<p>Now you can set the alarm on your memory and disk utilization as per your application\u2019s requirement.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>AWS provides its user the Cloud Monitoring service which is used to keep a check on the resources being used. It can be a great tool for developers and system administrators for cases like: Monitoring data\/graphs Setting up alarms Identify trends Take actions based on the state of cloud environment But AWS does not provide [&hellip;]<\/p>\n","protected":false},"author":90,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":5},"categories":[1174],"tags":[1172,248,1266,1268,1267],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11349"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/90"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=11349"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/11349\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=11349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=11349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=11349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}