How to setup Custom metrics on Ubuntu server EC2…

Custom metrics on Ubuntu server EC2

You can publish your own metrics to CloudWatch using the AWS CLI or an API. You can view statistical graphs of your published metrics with the AWS Management Console.

CloudWatch stores data about a metric as a series of data points. Each data point has an associated time stamp. You can even publish an aggregated set of data points called a statistic set.

Supported Systems

These monitoring scripts are intended for use with Amazon EC2 instances running Linux. The scripts have been tested on instances using the following Amazon Machine Images (AMIs), both 32-bit and 64-bit versions:

  • Amazon Linux 2014.09.2
  • Red Hat Enterprise Linux 6.6
  • SUSE Linux Enterprise Server 12
  • Ubuntu Server 16.04 and 14.04

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.

Prerequisites

With some versions of Linux, you must install additional modules before the monitoring scripts will work.

Amazon Linux AMI

  1. Log on to your instance. For more information, see Connect to Your Linux Instance.
  2. At a command prompt, install packages as follows:

sudo yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https

Red Hat Enterprise Linux

  1. Log on to your instance. For more information, see Connect to Your Linux Instance.
  2. At a command prompt, install packages as follows:

sudo yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA –y

sudo yum install zip unzip

SUSE Linux Enterprise Server

  1. Log on to your instance. For more information, see Connect to Your Linux Instance.
  2. At a command prompt, install packages as follows:

sudo zypper install perl-Switch perl-DateTime

sudo zypper install –y “perl(LWP::Protocol::https)”

Ubuntu Server

  1. Log on to your instance. For more information, see Connect to Your Linux Instance.
  2. At a command prompt, install packages as follows:

sudo apt-get update

sudo apt-get install unzip

sudo apt-get install libwww-perl libdatetime-perl

To download, install, and configure the monitoring scripts

  1. 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 http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip -O

  1. Run the following commands to install the monitoring scripts you downloaded:

unzip CloudWatchMonitoringScripts-1.2.1.zip

rm CloudWatchMonitoringScripts-1.2.1.zip

cd aws-scripts-mon

  1. Ensure that the scripts have permission to perform CloudWatch operations using one of the following options:
  • If you associated an AWS Identity and Access Management (IAM) role with your instance, verify that it grants permissions to perform the following operations:
    • cloudwatch:PutMetricData
    • cloudwatch:GetMetricStatistics
    • cloudwatch:ListMetrics
    • ec2:DescribeTags
  • Specify that you have given the role to your EC2 for using the cloudwatch or put the access key and secret key . But best practice says that we should follow with the role.
  1. To perform a simple test run without posting data to CloudWatch

./mon-put-instance-data.pl –mem-util –verify –verbose

  1. To collect all available memory metrics and send them to CloudWatch

./mon-put-instance-data.pl –mem-util –mem-used-incl-cache-buff –mem-used –mem-avail

You will see the Cloudwatch console as follow:

You will see the custom metrics for the linux system.By clicking on that you will get the different metrics like memory-used , memory available and memory utilization.

C:\Users\Jigisha\Desktop\Untitled.png

 

Jigisha Araniya.
AWS-team,
Electromech Corporation.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*