Grafana: The Ultimate Guide to Beautiful and Effective Monitoring Dashboards

Discover how Grafana turns raw data into actionable insights with stunning dashboards, making monitoring not just efficient but enjoyable!

Grafana: The Ultimate Guide to Beautiful and Effective Monitoring Dashboards

What is Grafana?

  • Grafana is a tool for visualizing and monitoring data. It creates dashboards and graphs to help you see and understand your data from sources like Prometheus or databases.

It is essential to read the previous blog of prometheus before continuing with this one, as it provides necessary context for understanding the current content.

You can refer to this document to write the Grafana service in docker-compose.yml. If you have been following my blogs, you will know that memorizing code is not necessary. Instead, we just need to consult the documentation and make minor adjustments to the code, such as changing the namespace and volume name.

Steps for Integrating Prometheus into Grafana:

  1. To integrate Prometheus into Grafana, begin by adding the Grafana service to the docker-compose.yml file:
#docker-compose.yml

version: "3.8"

networks:  #For the communication of two containers (notes-app & prometheus)
  monitoring:
    driver: bridge

volumes:
  prometheus_data:     #prometheus volume

  grafana_data:        #grafana volume

services:
  notes-app:
    build:
      context: django-notes-app/.    #Dockerfile is inside django-notes-app
    container_name: notes-app
    ports:
      - "8000:8000"
    networks:
      - monitoring

  prometheus:
    image: prom/prometheus:latest
    container_name: prometheus
    restart: unless-stopped
    networks:
      - monitoring

    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
      - prometheus_data:/prometheus              #Save prometheus volume here, which we declare at top
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
      - '--storage.tsdb.path=/prometheus'
      - '--web.console.libraries=/etc/prometheus/console_libraries'
      - '--web.console.templates=/etc/prometheus/consoles'
      - '--web.enable-lifecycle'
    ports:
      - "9090:9090"

  cadvisor:
    image: gcr.io/cadvisor/cadvisor:latest
    container_name: cadvisor
    ports:
      - "8080:8080"
    volumes:
    - /:/rootfs:ro          #cadvisor directly access root file system due to that all container data it gathers
    - /var/run:/var/run:rw  #Data of all tghe running processes it gather
    - /sys:/sys:ro          #
    - /var/lib/docker/:/var/lib/docker:ro   #Docker related files
    depends_on:
    - redis
    networks:
      - monitoring

  redis:
    image: redis:latest
    container_name: redis
    ports:
    - "6379:6379"

  node-exporter:
    image: prom/node-exporter:latest
    container_name: node-exporter
    restart: unless-stopped
    volumes:
      - /proc:/host/proc:ro
      - /sys:/host/sys:ro
      - /:/rootfs:ro
    command:
      - '--path.procfs=/host/proc'
      - '--path.rootfs=/rootfs'
      - '--path.sysfs=/host/sys'
      - '--collector.filesystem.mount-points-exclude=^/(sys|proc|dev|host|etc)($$|/)'
    ports:
      - "9100:9100"
    networks:
      - monitoring

  grafana:
    image: grafana/grafana-enterprise:latest
    container_name: grafana
    ports:
      - "3000:3000"
    volumes:
      - grafana_data:/var/lib/grafana
    networks:
      - monitoring
    restart: unless-stopped

    depends_on:
      - prometheus

Implement the changes.

docker compose up -d
  1. Add the Grafana 3000 port entry to the inbound rules of our EC2 instance. After adding the port entry, copy the public IP of the EC2 instance and enter it into the browser, followed by port 3000, as shown below.

The Grafana server is now up and running.

  1. Log in with the new user, and you will see the Grafana dashboard displayed as shown below:

  1. We want to do connection between Prometheus and Grafana so click on Connections → Add new connection → Search “Prometheus“ & click.

  • Click on Add new data source:

  • Enter the URL of the Prometheus server:

  • Click on Save & test, then proceed to building a dashboard to start creating a new dashboard.

  • Click on Add Visualization:

  • Click on Prometheus data source:

  • Create a query by clicking on Select metric:

  • To add visualization designs, click on Time series and follow the suggestions provided:

  • Click on "Back to Dashboard," located at the top right side of the menu bar.

  • Click on Add → Visualization.

  • Add another visualization and click on back to dashboard:

  • You can see it is available on dashboard.

  • Now we can check the errors from the last 30 minutes and add a visualization for that too:

  • Here you can see around 80% our CPU has been used, so if we added more 2-3 services in our docker compose then our CPU will be full. This is how visualization helps.

  • This is how our Grafana Dashboard will looks like, now we can change the panel name:

  • Similarly, I have included a map and a News panel to improve the dashboard's visual appeal.

  • Finally, this is the appearance of our completed dashboard:


Grafana Dashboard Templates:

There are many templates available for creating a Grafana Dashboard. You can easily find them by searching for "Grafana Dashboard templates" in your browser.

  1. Search for Prometheus and select the template you like.

  1. Click on “Copy ID to clipboard“

  1. Now go to our Grafana Dashboard and click on New and then Import:

  • Paste the ID and click on Load:

  • Select a Data source and Import:

  • You can see our Grafana Dashboard:

  • Let add another dashboard for Docker:

  1. To check on what basis this graph has been created, click on edit and check the query:

This is how Grafana operates. You can monitor your application easily using Prometheus and Grafana, with enhanced visualization options.


Happy Learning :)

Chetan Mohod ✨

For more DevOps updates, you can follow me on LinkedIn👇