# Connecting Grafana to CloudWatch for Monitoring

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053068848/b3275aa4-254d-416a-ab1d-dfeb9194b072.gif align="left")

Grafana

> **Contents:**  
> [Introduction](#c57f)  
> **Installation of Grafana**  
> [1\. Create AWS Account.](#5d4d)  
> [2\. Search for EC2 Service](#0d35)  
> [3\. Create Instances](#662c)  
> [4\. Start the Grafana Server](#186d)  
> **Integration of Grafana with AWS EC2**  
> [1\. IAM policy](#f8d9)  
> [2\. Choose CloudWatch Service](#1848)  
> [3\. Select Service](#ed33)  
> [4\. Add Datasource CloudWatch](#ee3b)  
> [5\. Select Graph and Metrics](#437d)

Basically, Grafana is an open-source program used for analytics and visualization. No matter where your data is kept, you can examine, validate, and display it with Grafana. Simply said, it offers several tools that may transform the data in your database into stunning graphs and visualizations.

The major features of Grafana are as follows:

1. **Visualize**
    
2. **Alerts**
    
3. **Open source**
    
4. **Unify**
    
5. **Explore logs**
    
6. **Display dashboards**
    
7. **Create and share reports**
    

In this article, we’ll concentrate on setting up Grafana on Ubuntu with AWS EC2 and integrating it with CloudWatch to monitor system performance and cut costs.

So, let’s begin with the installation of Grafana!!

1. You must first have a valid AWS account. I’m going to assume you already have one, but if not, click this link to make one.
    

[**AWS Management Console**  
\*Everything you need to access and manage the AWS Cloud - in one web interface Get additional help with support plans…\*aws.amazon.com](https://aws.amazon.com/console/)

2\. Following account creation, you may see the AWS dashboard as shown below:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053070468/23eedd0a-853f-4a6e-bf88-14b74111d6d9.png align="left")

AWS Dashboard

3\. You may now access the EC2 Dashboard by clicking on the AWS EC2 service after searching for it in the search box.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053071864/421fb79c-1cec-4777-8d69-fa0a6f07d4a8.png align="left")

Click on the EC2 Service above

4\. There are currently no instances active in the EC2 dashboard. I have multiple instances that I’ve generated on the Dashboard. The steps listed below must be followed in order to create an instance:

**a. Choose an Amazon Machine Image (AMI)**

**b. Choose an Instance Type.**

**c. Configure Instance Details.**

**d. Add Storage. (30 GB)**

**e. Add Tags. (optional)**

**f. Configure Security Group.**

**g. Review Instance Launch and Select Key Pair.**

Launch the instance after storing the key pair file (per file) in a safe location. Your newly created instance will appear on the EC2 dashboard. When it gets to the running state, it is first in the pending state. It’s accessible to you.

***NOTE: Do not share the “pem file” with anyone.***

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053074135/ee41b9f9-0488-4252-a450-25db95214cf3.png align="left")

Select an Instance you created

5\. You need to **SSH** into your most recent instance right now. Run the following command in your terminal from the location where you have your **pem file** to do this.

* **ssh -i “Your pem key”** [**ubuntu@your\_pubilcIPV4address**](mailto:ubuntu@your_pubilcIPV4address)
    

6\. You must provide a few commands for Grafana installation as soon as you enter the instance. The EC2 instructions to enter are listed below:

* **ubuntu@ip-172–31–42–33:~$ sudo wget** [**https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana\_5.2.4\_amd64.deb**](https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana_5.2.4_amd64.deb)
    
* **ubuntu@ip-172–31–42–33:~$ sudo apt-get install -y adduser libfontconfig**
    
* **ubuntu@ip-172–31–42–33:~$ sudo dpkg -i grafana\_5.2.4\_amd64.deb**
    

7\. Next step is that we need to modify our /etc/apt/sources.list file by adding a line to the bottom of it:

* **ubuntu@ip-172–31–42–33:~$ sudo nano /etc/apt/sources.list**
    

Scroll down all the way to the bottom using your **down-arrow key**. Add the following line at the bottom:

`deb` [`https://packagecloud.io/grafana/stable/debian/`](https://packagecloud.io/grafana/stable/debian/) `stretch main`

`Press CTRL+X and hit Y to confirm to save the file.`

8\. Now we need to add the Package Cloud key. This will allow us to install signed packages.

* **ubuntu@ip-172–31–42–33:~$ curl** [**https://packagecloud.io/gpg.key**](https://packagecloud.io/gpg.key) **| sudo apt-key add -**
    

9\. Now finally let’s see if we have everything successfully installed by using the following commands:

* **ubuntu@ip-172–31–42–33:~$ sudo apt-get update**
    
* **ubuntu@ip-172–31–42–33:~$ sudo apt-get install grafana**
    

10\. Now, Start the Grafana Server by executing the following commands:

* **ubuntu@ip-172–31–42–33:~$ sudo systemctl start grafana-server**
    

We can check that the server is running as expected by executing the following command:

* **ubuntu@ip-172–31–42–33:~$ sudo systemctl status grafana-server**
    

\=&gt; ***Your Grafana server is finally ready!!***

Open your Web Browser and enter the IP of your server followed by port 3000, like for example [**http://YourEC2ServerID:3000**](http://YourEC2ServerID:3000)

11\. You should then be able to see the Grafana Login Window.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053076292/51ee3bff-4dbe-43a6-803f-c4ad12832ddf.png align="left")

Grafana Server login Page

12\. You must now add your admin or user credentials and log in. You will then be requested to update your Grafana password.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053078431/c8f56250-a3d5-44d7-b1ba-84c2137e326f.png align="left")

Add credentials as Admin/User and login into the Account

13\. Save your new password now, and Grafana will display the dashboard as seen below:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053080723/283a4db3-2fa8-44e8-8a2b-99421ae628c8.png align="left")

Grafana Dashboard

### Finally, we will be integrating Grafana with AWS using the following steps:

1. You must first create an IAM policy from AWS since Grafana requires integration with AWS. Therefore, let’s **create an IAM policy**. Go to the AWS console and type **IAM** into the top search box. The sample photo is shown below.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053082790/349bb797-43c5-452d-a8b6-5419a5e84f49.png align="left")

Create an IAM policy from the AWS dashboard

2\. Now, as soon as you click on IAM you will the get **IAM dashboard**. Below is the snapshot.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053085136/6ab3a390-5751-4807-8511-ba4dff7fb183.png align="left")

IAM Dashboard

3\. Thereafter, you need to create an IAM policy. So, you can click on **Policies** present in the left panel. Below is the sample.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053087572/377329c3-0a6f-48b3-9ae6-50751af37b57.png align="left")

Policies

4\. To grant Grafana read access for the CloudWatch metric, you must now choose to **Create policy**. There is a window below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053089926/19cec083-817c-4ec7-ae59-6ef840f852f5.png align="left")

Create a policy

5\. Then, choose **CloudWatch** from the list of **services**, then **Action** to perform the action on Grafana, as shown below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053092009/ed637188-c119-4ddc-aea0-653bf4dae74e.png align="left")

Choose a service named CloudWatch

6\. You must now evaluate your newly generated policy and give it a name similar to the one below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053094109/14ba4efe-d994-4f8e-a220-ec476ed8a6ef.png align="left")

Review the Policy

7\. In order to create an IAM role, click **role** in the left panel of the IAM dashboard. This will bring up a list of all available IAM roles, as seen in the image below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053096350/d271fc6e-c65a-4163-9914-66daae904ab2.png align="left")

Create an IAM role

8\. Now move to **Create role** and give it a click, you will get something like the below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053098690/eb5a2baf-e52b-4b8a-b803-193796825a0d.png align="left")

After An IAM role is created

9\. The next step is to choose **Next** after selecting **AWS service** and **EC2** from the **Use case**. You must now add a role name and a permit as shown below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053101053/af6f3ee5-b60e-4902-a1ba-d600a4940ba5.png align="left")

Select AWS and EC2 Services

10\. Now in Add permission you need to search for the policy you created above. In my case, my IAM policy name is **Grafanapolicy**. So, add your policy like below sample snapshot.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053103353/cbf45fba-2b8c-4109-a444-bab7506395ff.png align="left")

Add Permissions

11\. Now, you can click on **Next** do the review of your role, and click on **Create role**. Below is the sample snapshot.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053105708/549e2cfd-541a-4149-a6b7-e051b0542173.png align="left")

12\. You will be able to see the role you created in the IAM Roles below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053108007/082fa846-66e4-411a-9cbc-e511fa9556a8.png align="left")

The role you created will appear here

13\. As a result, you must now establish an IAM user who has access to the IAM role and IAM policy you just created. Consequently, choose **Users** from the left side on the IAM dashboard and then click **Add User**.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053110473/a4b587ba-e7df-4480-97d6-7aaeacc2b54a.png align="left")

Create an IAM user

14\. Now give a name to your IAM user and provide other necessary information and click on **Next: Permission** like below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053112852/38eea5d0-0f82-4571-bdfe-e15636bc80cf.png align="left")

Provide a name for it

15\. By selecting **Attach existing policies directly** and looking for the IAM policy you generated, as shown in the sample screenshot below, you may now attach the permission.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053115164/b89748fe-9da0-4d03-bba6-2a396b8e4499.png align="left")

Attach the policies you created before

16\. Now click on **Next: Tags** &gt;&gt; click on **Review** and click on **Create user**.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053117508/2e3ee005-dea9-447a-aa80-20f7c231d4a4.png align="left")

Review and create the User

17\. Now go to the EC2 dashboard and select your recently created instance and do the same as the sample snapshot.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053119683/76083520-9282-47a8-b0ad-1a1104cac36c.png align="left")

EC2 Dashboard

18\. Then, in **Modify IAM role**, you must choose the IAM role you have recently established and click **save** as seen below. The most fascinating items are now available on Grafana.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053122001/4109c399-419c-443d-82e4-39eda2e2e7e7.png align="left")

Now you can get the most interesting things on Grafana.

19\. As a result, go to the Grafana dashboard, choose **Add Datasource** to add a data source, name the dashboard, and then choose **CloudWatch** from the Type box.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053124375/6c2bcccd-af32-42a9-9750-fb8827d98519.png align="left")

Add Datasource and select CloudWatch

20\. Give the CloudWatch information as shown in the sample snapshot below, then click **save and test**. A notification such as **Data source is working** will appear. If you receive a different message, there is a problem. Follow this blog closely, then.

You will get a Message Data Source is Working

21\. Once you’ve completed this step, it’s time to explore Grafana’s most intriguing insights via **AWS CloudWatch**. As a result, click the “+” symbol in the left panel, choose **Dashboard**, and then choose the **Graph** option to get a screen similar to the one below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053126367/b777d0db-45b5-44fa-ab77-c311d016f6ab.png align="left")

To view the most interesting insights from Grafana, Select Graphs

22\. After selecting the **Graph** option you will get the below snapshot. Then from the **panel title** select the **Edit** option like below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053128648/870f775f-727f-463a-a666-538435db650f.png align="left")

New Dashboard to select Metrics

23\. Thereafter you will be able to get the below screen, where you need to select **Metrics.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053131019/cb62d823-9c7f-4ccb-94f1-947f60712ad9.png align="left")

Add Metrics

24\. You may now see your desired metrics; In my case, I want to view the **CPU Utilization** of my EC2 instance. I selected my area, namespace, and metric and then I asked for the average statistics. I then chose my instance ID, and there you have it! You’ll see the graph look something like this:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053133133/24cc1cb7-8031-49f1-919b-ba5f2f88c6b2.png align="left")

The graph we get after all the Metrics selected

25\. Now, after getting this graph we want to set it in the dashboard. So, click on the save button and give the name to this graph like below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053135567/d96b3ccb-0654-44ef-b503-e373928c4195.png align="left")

Save the graph for future Purposes

26\. Now you will be able to see the graph on the dashboard like below.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1703053137985/738fd22a-fdde-43f4-aaa8-14bfb1fb1752.png align="left")

The Graph appears on the Dashboard

So, that’s pretty much all. Procedure by which we connected to CloudWatch by installing Grafana on Ubuntu and utilizing AWS EC2. I hope this was enough informative for everyone’s processes.

> I hope this article was informative and provided you with the details you required. If you have any questions while reading the blog, message me on [Instagram](https://www.instagram.com/acanubhav94/) or [LinkedIn](https://www.linkedin.com/in/anubhav-chaturvedi-a7465a72/).For any kind of work related to DevOps, Site Reliability you can contact me at [helpmeanubhav@gmail.com](mailto:helpmeanubhav@gmail.com)

> Thank You…
