---
title: Configure CloudWatch Logs Agent on a Running EC2 Linux Instance and Monitor on Cloudwatch dashboard.
tags: AWS, EC2, EBS, size, RAM, Utilization, cloudwatch
description:
---
# Configure CloudWatch Logs Agent on a Running EC2 Linux Instance and Monitor on Cloudwatch dashboard
## What we need?
- Login credential of your AWS account :laughing:.
- Access to your EC2 instance.
## Steps need to perform on AWS console.
#### Configure Your IAM Role or User for send EC2 logs on CloudWatch.
##### Create policy
- Open console and go on [IAM](https://console.aws.amazon.com/iam/) page
- In the navigation pane, choose **Polices**.
- Click on **create policy**.
- Click on JSON tab in for create policy and paste JSON given below.
```
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStreams"
],
"Resource": [
"arn:aws:logs:*:*:*"
]
}
]
}
```
- Click on review policy.
- Give a policy name and descrption.
- Click on create policy.
- :tada: It's Done.
##### Create Role
- Go on Roles from navigation pane.
- Click on create role.
- Chosse a service will use the role click on **EC2**.
- Click next.
- Attach a policy you just created (you can search using policy name).
- Click next next till it's not ask for role name.
- Give role name and description.
- click on create role.
- :tada: It's Done.
## Next steps on your EC2 instance
- You need to perform some of command given below.
`sudo yum update -y`
`sudo yum install -y awslogs` Install awslogs package
`sudo systemctl start awslogsd` Start awslogs service
- (Optional) If you want to check for any error logged or not then you can go throw `/var/log/awslogs.log` file.
- :tada: No it's not over here.
- Need to install scripts for monitior EBS volumes.
###### For amazon linux
`sudo yum install -y perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https perl-Digest-SHA.x86_64`
###### For Ubuntu
`sudo apt-get update`
`sudo apt-get install unzip`
`sudo apt-get install libwww-perl libdatetime-perl`
- After get repo perform a simple test run without posting data to CloudWatch
`./mon-put-instance-data.pl --mem-util --verify --verbose`
- To collect all available memory metrics and send them to CloudWatch
`./mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --mem-used --mem-avail`
### Set a cron here to get every second data
- Use `crontab -e`
- Add new cron in that file
`* * * * * ~/aws-scripts-mon/mon-put-instance-data.pl --mem-used-incl-cache-buff --mem-util --disk-space-util --disk-path=/ --from-cron`
##### If you get any issue then you can refer a links given below.
## Configure Dashboard on Cloudwatch
- Go on [Cloudwatch](https://console.aws.amazon.com/cloudwatch) page.
- Click on dashboard in navigation pane.
- Click on create dashboard button.
- Give a dashboard name and click on create dashboard.
- Click on Add widget.
- Choose your widget type and click on configure.
- Select your Metric from Custom Namespaces.
- Click on create widget.
- :tada: It's finally done.
## Thanks a lot
---
##### Referance link
[Watch on EC2 instance](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/QuickStartEC2Instance.html)
[Monitoring Scripts](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/mon-scripts.html)
[Configure Cloudwatch Dashboard](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/add_remove_text_dashboard.html)