DevOps, Day - 74

DevOps, Day - 74

Connecting EC2 with Grafana.

  1. Launch EC2 Instances:

    Launch an Amazon Linux EC2 instance for the Linux server and a Windows EC2 instance for the Windows server. Make sure both instances have the necessary security groups and firewall rules to allow traffic to and from Grafana. Install any necessary monitoring agents or exporters on these instances.

  2. Set Up Grafana:

    (install in Linux instance)

     sudo apt update
     sudo apt upgrade
    
     sudo apt-get install -y software-properties-common
     sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
     wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
     sudo apt-get update
     sudo apt-get install grafana
    
  3. Start Grafana

     sudo systemctl status grafana-server
     sudo systemctl start grafana-server
    

    Edit inbound rules and allow 3000 port

    Copy your public IP and paste it into the browser followed by 3000 port no.

    By default, Grafana runs on port 3000. You can access it in your web browser by navigating to http://ur_Public-IP:3000.

    • The default login credentials are:

      • Username: admin

      • Password: admin

      • You will be prompted to change your password on the first login.

  4. Install Prometheus:

     sudo apt update
     sudo apt install prometheus
    
  5. Check the version:

     prometheus --version
    

  6. Configure Prometheus:

    In Prometheus, you'll need to define target jobs for scraping metrics from your Linux and Windows servers. You can do this by modifying the prometheus.yml configuration file.

    For Linux, you might use something like this:

     scrape_configs:
       - job_name: 'linux-server'
         static_configs:
           - targets: ['<Linux-EC2-Instance-IP>:9100']
    

    For Windows, you might use something like this (assuming you have a Prometheus exporter for Windows metrics):

    • Before that create an IAM role

    • Search for "AmazonSSMManagedInstanceCore" --> Next

    • Name the role --> Create role

    • Our role is created

  7. Assign the IAM Instance Profile to Your EC2 Instance:

    • Navigate to your EC2 instances in the AWS Management Console.

    • Select the Windows EC2 instance that you want to connect to.

    • Choose "Actions" > "Security" > "Modify IAM Role."

    • Select the IAM instance profile you created earlier and attach it to your instance.

  8. Connect with the Windows EC2

    • Search for "System Manager" in the service section.

    • scroll down and navigate to "Session Manager"

    • Click on "Start Sessions"

    • It will take some time to display the instance, Once u see it, click on Next.

    • Click Next in "Specify Session Document" and Click "Start Session"

    • Finally, it is started successfully.

  9. Now write the Prometheus config file in it.

     scrape_configs:
       - job_name: 'windows-server'
         static_configs:
           - targets: ['<Windows-EC2-Instance-IP>:9182']
    
  10. Ensure that your security groups allow Prometheus to access these ports.

  11. Configure Data Sources in Grafana:

    In Grafana, you need to add Prometheus as a data source. Go to the Grafana web interface, navigate to "Connection" > "Data Sources," and add Prometheus as a data source.

    Paste ur public_IP followed by 9090 port...

    Successfully queried the Prometheus API.

  12. Create Dashboards:

    Create dashboards in Grafana to visualize the metrics collected by Prometheus. You can create separate dashboards for Linux and Windows servers, and add panels to display various metrics (CPU usage, memory usage, network traffic, etc.).

  13. Monitor Your Servers:

    You can now monitor your Linux and Windows servers using Grafana. The metrics will be collected by Prometheus, and displayed in Grafana dashboards, and you can set up alerts to be notified of any issues.

    Click on "Select Metric" and select whichever metric you need...

    Click "Apply" at the top right.

    This is a panel

    You can even set the range


Thank you so much for reading

Follow me on LinkedIn to see interesting posts like this : )

Linkedin

Β