# DevOps Project: System Monitoring in AWS instance

Today we will be trying to do the system monitoring of our Linux system. Once this system monitoring is implemented in our local machine successfully we will be moving this to our ec2 instance in AWS and setting the cron job.

### What we will be monitoring in our system?

* Disk Usage
    
* Memory Usage
    
* CPU usage
    

**The command for CPU usage: cpu\_usage.sh**

```plaintext
top
#or
cat /proc/cpuinfo
#or
 ps -eocomm,pcpu | grep -E -v '(0.0)'
```

**The command for memory usage: mem\_usage.sh**

```plaintext
 ps -eocomm,pmem | grep -E -v '(0.0)'
```

**The command for disk usage: disk\_usage.sh**

```plaintext
df -h
```

We will be creating a main.sh file where we will source all the above files (i.e. CPU, mem, and disk). In this position, we will be giving the option to choose what the user wants to check either CPU usage or disk usage or memory usage, or all. Using the case statement the user will be able to achieve what parameter they want to check.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1702894170124/6b4884db-816a-4c52-9778-d56b34e798e3.png align="center")

In this project, we will be performing different file operations:

* creating files
    
* checking whether the file is present or not
    
* listing all files and directories
    
* removing the files once the task is done
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1702894485626/15ebf8db-7ce0-4f52-ad84-86d7458ca450.png align="center")

On executing this, we will be generating a file as below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1702894699712/a7915a1b-1844-4654-ac8e-94deb6e0a8c8.png align="center")

The generated file is in the .txt extension. We will be converting it to the PDF using cupsfilter.

```plaintext
cupsfilter "$output_file".txt >"$output_file".pdf
```

The pdf file will be emailed to the user and once the file is sent we will remove these files from the system.

In this project, the password is generated for sending the email. For generating the password we use this link: [https://myaccount.google.com/apppasswords](https://myaccount.google.com/apppasswords)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1702895202486/0a8bc9a6-af18-4abb-985c-c7d50dfb1514.jpeg align="center")

The email sent is successfully done.

Now we will copy these files to our ec2 instance and set the cron job.

### Creating an EC2 instance

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1702896068583/a1ef66bc-25e1-44de-9680-e5f396610a1a.png align="center")

### Copying files to ec2 instance

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1702896134908/dbde9c5b-202b-4d50-b178-d426db439716.png align="center")

Now creating the cron job for this script.

```plaintext
crontab -e
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1702896454626/5bd1c004-aae3-43d6-ada5-fd2efb2d11ed.png align="center")

We have set the cronjob successfully. The script will be executed every hour and the report will be generated.

Since I have mentioned some basic code and some snippets of the project, you can try it yourself using the following repo link:

repo: [https://github.com/imsubash-devops/system\_monitor](https://github.com/imsubash-devops/system_monitor)
