Monitor Nginx with Grafana Dashboard

Monitor Nginx with Grafana Dashboard

#day75 of #90daysofdevops

ยท

3 min read

Introduction:

Welcome to Day 75 of #90daysofdevops! In today we'll be setting up a dashboard to visualize Nginx logs.

Smiling.Gif GIF - Smiling Rajinikanth Happy Face GIFs


Pre-requisites:

  1. Amazon EC2 Instance

    • Ensure the availability of an Amazon EC2 instance to serve as the host for Docker containers and the monitoring tools.

  2. Grafana, Loki, and Promtail Installed

    • Install Grafana, Loki, and Promtail to set up the monitoring and log aggregation stack on the EC2 instance.

        • Grafana: The visualization and monitoring tool.

          * Loki: The log aggregation system.

          * Promtail: The agent responsible for collecting and forwarding logs to Loki.

  3. If the necessary tools are not installed, follow the step-by-step instructions provided in the referenced blog post for comprehensive guidance.


Certainly! Here are the step-by-step instructions:

Step 1: Install Nginx

sudo apt update
sudo apt install nginx
sudo systemctl start nginx

Step 2: Configure Promtail to Read Nginx Logs

  1. Create a configuration file for Promtail, e.g., promtail-config.yml:

     server:
       http_listen_port: 9080
       grpc_listen_port: 0
     positions:
       filename: /tmp/positions.yaml
     clients:
       - url: http://localhost:3100/loki/api/v1/push
     scrape_configs:
       - job_name: nginx
         static_configs:
           - targets:
               - localhost
             labels:
               job: nginx
               __path__: /var/log/nginx/*log
    

  2. Restart the promtial container

     docker restart <continer_id>
    

Step 3: Open Grafana in the Browser

  1. Access Grafana in your web browser (typically at http://localhost:3000).

  2. Log in with the default credentials (admin/admin).

Step 4: Add Loki as a Data Source

  1. In Grafana, go to "Settings" > "Data Sources" > "Add your first data source."

  2. Choose "Loki" from the list.

  3. Set the URL to http://localhost:3100.

Step 5: Create a Loki Query in Grafana

  1. Go to "Explore" in Grafana.

  2. Choose the Loki data source.

  3. Use a query like {job="nginx"} to view Nginx logs.

Step 6: Create a Dashboard in Grafana

  1. Go to the "+" menu in Grafana and choose "Dashboard."

  2. Click "Add new panel" and select "Loki" as the data source.

  3. Create visualizations and customize your dashboard with Nginx log data.


Conclusion:

Congratulations on successfully setting up the Nginx monitoring dashboard using Grafana, Loki, and Promtail

Sushichaeng Cartoon GIF - Sushichaeng Cartoon Cartoon Network GIFs


Connect with me:)

Thank you for diving into this blog with me! I trust you found the information both helpful and enlightening. To stay updated on the latest in DevOps ๐Ÿš€, make sure to follow me. Remember, staying informed means staying ahead in the dynamic world of DevOps!

Feel free to connect with me on:

LinkedIn

Twitter

GitHub

For more updates and engaging discussions on DevOps, let's connect! ๐Ÿš€ #DevOpsCommunity

ย