# Day 74 Task: Connecting EC2 with Grafana

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707229469668/1b941dbb-4076-4d4c-864c-411096f2ad7b.png align="center")

### **🔶 Task: Connect a Linux and one Windows EC2 instance with Grafana and monitor the different components of the server.**

To set up monitoring for a Linux and a Windows EC2 instance using Grafana, you'll need to follow these general steps:

1. **Set Up Grafana Server (Already Covered):**
    
    * As mentioned in the previous response, you should have Grafana installed and running on a Linux EC2 instance. Make sure it's accessible via a web browser.
        
2. **Install Prometheus on Linux EC2 (Monitoring Server):**
    
    * Prometheus is a popular monitoring and alerting toolkit that can scrape metrics from various targets, including EC2 instances.
        
    * Install Prometheus on your Linux EC2 instance. You can download it from the Prometheus website and follow the installation instructions.
        
3. **Configure Loki:**
    
    * ```plaintext
              #To download Loki Config
              wget https://raw.githubusercontent.com/grafana/loki/v2.8.0/cmd/loki/loki-local-config.yaml -O loki-config.yaml
        ```
        
4. ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707138300617/e323aa69-b796-4961-83f1-59d39563a477.png align="center")
    
5. Install Loki and Promtail using Docker
    
    Download Loki Config:
    
    ```plaintext
     wget https://raw.githubusercontent.com/grafana/loki/v2.8.0/cmd/loki/loki-local-config.yaml -O loki-config.yaml
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707138363955/4edd0f11-f496-49df-8f7d-66f58aca0d40.png align="center")
    
    Run Loki Docker container:
    
    ```plaintext
     docker run -d --name loki -v $(pwd):/mnt/config -p 3100:3100 grafana/loki:2.8.0 --config.file=/mnt/config/loki-config.yaml
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707138432145/5b767ae3-b855-423b-a6ec-60b364d675c0.png align="center")
    
    Download Promtail Config:
    
    ```plaintext
     wget https://raw.githubusercontent.com/grafana/loki/v2.8.0/clients/cmd/promtail/promtail-docker-config.yaml -O promtail-config.yaml
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707138486464/f7a1d08a-72be-4d9e-881c-f72793bd246a.png align="center")
    
6. Run Promtail Docker container:
    
    ```plaintext
     docker run -d --name promtail -v $(pwd):/mnt/config -v /var/log:/var/log --link loki grafana/promtail:2.8.0 --config.file=/mnt/config/promtail-config.yaml
    ```
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707138519723/a70eb3d1-9093-4d5e-bd21-4d53ebc6a203.png align="center")
    
7. **Configure Grafana Data Source:**
    
    * Access your Grafana web interface and log in.
        
    * Configure Loki as a data source in Grafana.
        
        * Go to "Configuration" &gt; "Data Sources" &gt; "Add data source."
            
        * Choose "Loki" as the data source type.
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707224348237/33ae600e-c482-4a33-8bc3-e343df0a1166.png align="center")
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707224440710/5c4b876a-7616-4c0a-ac06-fb854b13828d.png align="center")
            
            ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707224486641/96271024-5fa1-4993-a77f-aa87a16e45b3.png align="center")
            
        * Provide the Loki server URL (usually http://:9090).
            
8. **Create Grafana Dashboards:**
    
    * Create Grafana dashboards to visualize the metrics collected from both instances.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707225832758/b3674e9a-29ed-4db2-87c8-e7f26eb49ce4.png align="center")
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707225922519/4b22770a-dccb-4e37-8e2e-ef3700c6ca83.png align="center")
        
    * You can add panels for CPU usage, memory usage, disk space, network activity, and any other metrics you want to monitor.
        
9. **Monitor and Analyze:**
    
    * With Prometheus and Grafana configured, you can now monitor and analyze the different components of your Linux and Windows EC2 instances.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1707229469668/1b941dbb-4076-4d4c-864c-411096f2ad7b.png align="center")
        

Remember to secure your setup, especially when monitoring Windows instances, by implementing proper access controls, firewalls, and authentication mechanisms.

Please note that this is a high-level overview, and specific configurations may vary based on your requirements and the software versions you use. Always refer to the official documentation of Prometheus, Node Exporter, Grafana, and the exporters for detailed setup instructions.

***Happy Learning :)***

Lokesh Telange

Thank you for reading! Your support means the world to me. Let's keep learning, growing, and making a positive impact in the tech world together.
