{"id":947,"date":"2016-06-21T08:44:35","date_gmt":"2016-06-21T08:44:35","guid":{"rendered":"http:\/\/cloudkul.com\/blog\/?p=947"},"modified":"2025-02-07T11:05:29","modified_gmt":"2025-02-07T11:05:29","slug":"create-custom-metrics-aws-cloudwatch","status":"publish","type":"post","link":"https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/","title":{"rendered":"Create Custom metrics on AWS Cloudwatch"},"content":{"rendered":"\n<p>The Cloudwatch service of AWS is very useful for developers as well as for server admins because it helps them find the bottleneck in their application architecture.<\/p>\n\n\n\n<p>AWS provides lots of pre-defined metrics to detect the issues regarding the system and predefined services like CPU Limit, Disk Usage, Network Data, etc.<\/p>\n\n\n\n<p>But if you want to monitor your system based on other specifications then you can achieve it with the help of custom metrics.<\/p>\n\n\n\n<p>To create a custom metric for your system you have to use the aws cli because it helps you to put data on the cloudwatch panel.<\/p>\n\n\n\n<p>You can <a href=\"https:\/\/aws.amazon.com\/cli\/\">download the aws cli<\/a> for your OS distribution and configure it with the \u201caws configure\u201d command which asks you for the following parameters-:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">AWS Access Key ID [None]: ACCESS KEY ID OF YOUR IAM USER\nAWS Secret Access Key [None]: SECRET KEY OF YOUR IAM USER\nDefault region name [None]: REGION NAME for ex-: us-west-2\nDefault output format [None]: ENTER<\/pre>\n\n\n\n<p>After installing the AWS CLI, grab the value you want to create metrics for, such as the server&#8217;s free RAM.<\/p>\n\n\n\n<p>To grab the value of FREE RAM you can use the following bash script-:<\/p>\n\n\n\n<p>SAVE this script with script.sh<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">#START OF SCRIPT\n\nMEMFREE=$(egrep -o \"MemFree:\\s*([0-9]*)\" \/proc\/meminfo | egrep -o \"[0-9]*\")\n\nBUFFERS=$(egrep -o \"Buffers:\\s*([0-9]*)\" \/proc\/meminfo | egrep -o \"[0-9]*\")\n\nCACHED=$(egrep -o \"\\bCached:\\s*([0-9]*)\" \/proc\/meminfo | egrep -o \"[0-9]*\")\n\necho $MEMFREE\n\necho $BUFFERS\n\necho $CACHED\n\nFREEMEM=`expr $MEMFREE + $BUFFERS + $CACHED`\n\necho $FREEMEM\n\n\/usr\/local\/bin\/aws cloudwatch put-metric-data --namespace \"MyNameSpace\" --metric-name \"FREE RAM\" --value $FREEMEM --region us-west-2\n\n#END OF SCRIPT<\/pre>\n\n\n\n<p>The script includes the AWS CLI command to send data to CloudWatch. Let&#8217;s review its parameters:<\/p>\n\n\n\n<ul>\n<li>namespace -: It resembles the unique namespace of your metric to differentiate from other custom or predefined metrics for ex-: &#8211;namespace \u201cMyNameSpace\u201d<\/li>\n\n\n\n<li>metric-name -: It defines the metric name which we used to store our metric data for ex-: &#8211;metric-name \u201cFREE RAM\u201d<\/li>\n\n\n\n<li>value -: it resembles the exact value of our metric at a particular period for ex-: &#8211;value 56<\/li>\n\n\n\n<li>timestamp -: it helps to map the timestamp with the values of metrics for ex-: &#8211;timestamp 2016-06-14T12:00:00<\/li>\n\n\n\n<li>region -: It defines the region in which our server is running for ex-: &#8211;region us-west-2<\/li>\n<\/ul>\n\n\n\n<p>Now create a crontab entry of script.sh in your server for every minute so that it will send data to Cloudwatch periodically every minute.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">CRONTAB ENTRY<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">* * * * * .\/script.sh<\/pre>\n\n\n\n<p>Now go to the cloudwatch panel and observe the graph of your metrics.<\/p>\n\n\n\n<p>Now you can automate various tasks based on your custom metrics for ex-:<\/p>\n\n\n\n<ol>\n<li>You can create an alarm on Cloudwatch custom metrics to detect any abnormal activity.<\/li>\n\n\n\n<li>You can also create an alarm to autoscale your<a href=\"https:\/\/cloudkul.com\/blog\/aws-ec2-and-its-pricing-plans\/\"> EC2 instances<\/a> based on your custom metrics.<\/li>\n<\/ol>\n\n\n\n<p>CloudWatch custom metrics let you manage server needs based on your parameters and analyze logs more efficiently with graphs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Need Support?<\/h2>\n\n\n\n<p>Thank You for reading this Blog!<\/p>\n\n\n\n<p>For further more interesting blogs, keep in touch with us. If you need any kind of support, simply raise a ticket at&nbsp;<strong><a href=\"https:\/\/webkul.uvdesk.com\/en\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/webkul.uvdesk.com\/en\/<\/a>.<\/strong><\/p>\n\n\n\n<p><strong>For further help or queries, please&nbsp;<a href=\"https:\/\/cloudkul.com\/contact\/\">contact<\/a>&nbsp;us or raise a&nbsp;<a href=\"https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/\">ticket<\/a>.<\/strong><\/p>\n\n\n<div class=\"wk-share-icons\">\n<hr class=\"horizontal-line-break\" \/>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>The Cloudwatch service of AWS is very useful for developers as well as for server <a class=\"text-primary\" title=\"read more\" href=\"https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":6,"featured_media":952,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[32,45,46,47],"tags":[16,48,50,49],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Create Custom metrics on AWS Cloudwatch - Cloudkul<\/title>\n<meta name=\"description\" content=\"The Cloudwatch service of AWS is very useful for developers as well as for server admins because it helps them find the bottleneck in their application architecture.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Create Custom metrics on AWS Cloudwatch - Cloudkul\" \/>\n<meta property=\"og:description\" content=\"The Cloudwatch service of AWS is very useful for developers as well as for server admins because it helps them find the bottleneck in their application architecture.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudkul\" \/>\n<meta property=\"article:published_time\" content=\"2016-06-21T08:44:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-07T11:05:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2016\/06\/AWS-CloudWatch.png\" \/>\n\t<meta property=\"og:image:width\" content=\"848\" \/>\n\t<meta property=\"og:image:height\" content=\"422\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Nitin Agnihotri\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/\",\"url\":\"https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/\",\"name\":\"Create Custom metrics on AWS Cloudwatch - Cloudkul\",\"isPartOf\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\"},\"datePublished\":\"2016-06-21T08:44:35+00:00\",\"dateModified\":\"2025-02-07T11:05:29+00:00\",\"author\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/2891deba97a03939d99419a3ac3407a4\"},\"description\":\"The Cloudwatch service of AWS is very useful for developers as well as for server admins because it helps them find the bottleneck in their application architecture.\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Create Custom metrics on AWS Cloudwatch\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#website\",\"url\":\"https:\/\/cloudkul.com\/blog\/\",\"name\":\"Cloudkul\",\"description\":\"Host your eCommerce Store on AWS with Optimized Performance\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudkul.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/2891deba97a03939d99419a3ac3407a4\",\"name\":\"Nitin Agnihotri\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/78eef67ca93349ba049e7db9e3481aa9?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/78eef67ca93349ba049e7db9e3481aa9?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g\",\"caption\":\"Nitin Agnihotri\"},\"url\":\"https:\/\/cloudkul.com\/blog\/author\/nitin124\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Create Custom metrics on AWS Cloudwatch - Cloudkul","description":"The Cloudwatch service of AWS is very useful for developers as well as for server admins because it helps them find the bottleneck in their application architecture.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/","og_locale":"en_US","og_type":"article","og_title":"Create Custom metrics on AWS Cloudwatch - Cloudkul","og_description":"The Cloudwatch service of AWS is very useful for developers as well as for server admins because it helps them find the bottleneck in their application architecture.","og_url":"https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/","og_site_name":"Cloudkul","article_published_time":"2016-06-21T08:44:35+00:00","article_modified_time":"2025-02-07T11:05:29+00:00","og_image":[{"width":848,"height":422,"url":"https:\/\/cloudkul.com\/blog\/wp-content\/uploads\/2016\/06\/AWS-CloudWatch.png","type":"image\/png"}],"author":"Nitin Agnihotri","twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/","url":"https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/","name":"Create Custom metrics on AWS Cloudwatch - Cloudkul","isPartOf":{"@id":"https:\/\/cloudkul.com\/blog\/#website"},"datePublished":"2016-06-21T08:44:35+00:00","dateModified":"2025-02-07T11:05:29+00:00","author":{"@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/2891deba97a03939d99419a3ac3407a4"},"description":"The Cloudwatch service of AWS is very useful for developers as well as for server admins because it helps them find the bottleneck in their application architecture.","breadcrumb":{"@id":"https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/cloudkul.com\/blog\/create-custom-metrics-aws-cloudwatch\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Create Custom metrics on AWS Cloudwatch"}]},{"@type":"WebSite","@id":"https:\/\/cloudkul.com\/blog\/#website","url":"https:\/\/cloudkul.com\/blog\/","name":"Cloudkul","description":"Host your eCommerce Store on AWS with Optimized Performance","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudkul.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/2891deba97a03939d99419a3ac3407a4","name":"Nitin Agnihotri","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/78eef67ca93349ba049e7db9e3481aa9?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/78eef67ca93349ba049e7db9e3481aa9?s=96&d=https%3A%2F%2Fs.gravatar.com%2Favatar%2F6148c37469011bc2f8e491ca8f5de495%3Fs%3D80&r=g","caption":"Nitin Agnihotri"},"url":"https:\/\/cloudkul.com\/blog\/author\/nitin124\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/947"}],"collection":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/comments?post=947"}],"version-history":[{"count":17,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/947\/revisions"}],"predecessor-version":[{"id":19800,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/posts\/947\/revisions\/19800"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media\/952"}],"wp:attachment":[{"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/media?parent=947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/categories?post=947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudkul.com\/blog\/wp-json\/wp\/v2\/tags?post=947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}