Amazon cloud watch is a robust monitoring mechanism for the entire AWS infrastructure which includes EC2 instances, S3, ELB etc. We can able to track wide verity of metrics like CPU, disk,network traffic, available storage space,memory ( using custom metrics) in cloud watch
AWS also provides access to system and application logs custom alarms that provides real time notification when specific metric appear in logs or when certain events take place .
while creating the instances , by default we have below metrics for monitoring in the EC2 instances
1. CPU utilization
2. Disk reads/Disk read operations
3. Disk writes/Disk write operations
4. Network in/Network out
5. Network packets in/Network packets out
6. Status check failed count
7. Instance Status check failed
8.System status check failed
9.CPU credit usage
10. CPU credit balance
So as per that we have only limited resources available in monitoring metrics. We may need to find out the solution to add more metrics on custom level
1. First we need to create the IAM role for cloud watch administration
login to AWS console-services-IAM-roles and create a new role as below
2. click on the EC2 from the services to use this role and click on the permissions we will get the policy details which is ready to attach the role
3. select the policy called "CloudwatchAgentServerPolicy" from the filter policies option
4. Provide the role name as "cloudwatchagentrole" and create the role
5. Now we have to attach this role to an EC2 instance . select the instance which we want to install the agent and go to actions - instance settings-attach/replace IAM role
6. Login to the instance and download the agent using the below link
https://s3.amazonaws.com/amazoncloudwatch-agent /linux/amd64/latest/AmazonCloudWatchAgent.zip
7. Unzip & Install the agent using the below command
8.Let's configure the metrics which is need to collect and send to the cloud watch , we can configure agent using below command
9. start the agent using below command
10. Now login to the cloudwatch console and click on metrics we can see the CWagent metrics configured
Also if you check the logs from Cloudwatch-Log groups-messages we can see the logs which we have added as a metric in agent from /var/log/messages
Configuring the custom DB metric using boto3
***********************************************************************
from boto.ec2.cloudwatch import connect_to_region
import MySQLdb
import boto.ec2.cloudwatch
db=MySQLdb.connect("dbserver.c5g5m1fcix6x.us-west-2.rds.amazonaws.com","dbadmin","Onm0bile","dbserver")
cursor=db.cursor()
n=cursor.execute("select * from GetActiveSessions")
n1=cursor.fetchone()
s=str(n1)
table=string.maketrans( '', '', )
number=s.translate(table,"(){}<>,L")
numbers=int(number)
reg='ap-northeast-1'
conn_cw=boto.ec2.cloudwatch.connect_to_region(reg,aws_access_key_id=’<access key d>’,aws_secret_access_key=’secret access key>')
conn_cw.put_metric_data(namespace='my_namespace',name='my_metric',value=numbers,dimensions={'InstanceId':'i-a1b2c3d4'})
*****************************************************************************
Custom metric dashboard for DB
Thank you for reading ...
AWS also provides access to system and application logs custom alarms that provides real time notification when specific metric appear in logs or when certain events take place .
cloud watch mechanism
while creating the instances , by default we have below metrics for monitoring in the EC2 instances
1. CPU utilization
2. Disk reads/Disk read operations
3. Disk writes/Disk write operations
4. Network in/Network out
5. Network packets in/Network packets out
6. Status check failed count
7. Instance Status check failed
8.System status check failed
9.CPU credit usage
10. CPU credit balance
So as per that we have only limited resources available in monitoring metrics. We may need to find out the solution to add more metrics on custom level
1. First we need to create the IAM role for cloud watch administration
login to AWS console-services-IAM-roles and create a new role as below
2. click on the EC2 from the services to use this role and click on the permissions we will get the policy details which is ready to attach the role
4. Provide the role name as "cloudwatchagentrole" and create the role
6. Login to the instance and download the agent using the below link
https://s3.amazonaws.com/amazoncloudwatch-agent /linux/amd64/latest/AmazonCloudWatchAgent.zip
7. Unzip & Install the agent using the below command
8.Let's configure the metrics which is need to collect and send to the cloud watch , we can configure agent using below command
9. start the agent using below command
10. Now login to the cloudwatch console and click on metrics we can see the CWagent metrics configured
Also if you check the logs from Cloudwatch-Log groups-messages we can see the logs which we have added as a metric in agent from /var/log/messages
Configuring the custom DB metric using boto3
***********************************************************************
from boto.ec2.cloudwatch import connect_to_region
import MySQLdb
import boto.ec2.cloudwatch
db=MySQLdb.connect("dbserver.c5g5m1fcix6x.us-west-2.rds.amazonaws.com","dbadmin","Onm0bile","dbserver")
cursor=db.cursor()
n=cursor.execute("select * from GetActiveSessions")
n1=cursor.fetchone()
s=str(n1)
table=string.maketrans( '', '', )
number=s.translate(table,"(){}<>,L")
numbers=int(number)
reg='ap-northeast-1'
conn_cw=boto.ec2.cloudwatch.connect_to_region(reg,aws_access_key_id=’<access key d>’,aws_secret_access_key=’secret access key>')
conn_cw.put_metric_data(namespace='my_namespace',name='my_metric',value=numbers,dimensions={'InstanceId':'i-a1b2c3d4'})
Custom metric dashboard for DB
Thank you for reading ...
No comments:
Post a Comment