Creating Your First Grafana Dashboard with Prometheus Metrics

mdshamsfiroz
3 min readOct 31, 2024

--

Monitoring your systems is crucial for maintaining performance and reliability. While Prometheus excels at collecting and storing metrics, Grafana shines in visualizing this data. In this guide, we’ll walk through installing Grafana and creating a dashboard to display key system metrics collected by Prometheus.

Prerequisites

Before we begin, ensure you have:

  1. Prometheus set up and collecting metrics
  2. A system to install Grafana on (we’ll use Ubuntu in this example)

Step 1: Installing Grafana

Let’s start by installing Grafana on our Ubuntu system:

# Add the Grafana GPG key
sudo apt-get install -y software-properties-common
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
curl https://packages.grafana.com/gpg.key | sudo apt-key add -
# Update package list and install Grafana
sudo apt-get update
sudo apt-get install grafana
# Start Grafana service
sudo systemctl start grafana-server
sudo systemctl enable grafana-server

Step 2: Accessing Grafana

Once installed, you can access Grafana by opening a web browser and navigating to http://localhost:3000. The default login credentials are:

  • Username: admin
  • Password: admin

You’ll be prompted to change the password on your first login.

Step 3: Adding Prometheus as a Data Source

  1. In the Grafana UI, click on the gear icon (⚙️) in the left sidebar to open the Configuration menu
  2. Select “Data Sources”
  3. Click “Add data source”
  4. Choose “Prometheus” from the list
  5. In the HTTP section, set the URL to your Prometheus server (e.g., http://localhost:9090)
  6. Click “Save & Test” to ensure the connection is working

Step 4: Creating Your First Dashboard

Now, let’s create a dashboard to visualize some key system metrics:

  1. Click the “+” icon in the left sidebar and select “Dashboard”
  2. Click “Add new panel”

Panel 1: CPU Usage

  1. In the query editor, enter the following PromQL query:
100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)

2. This query calculates the CPU usage percentage

3. Set the panel title to “CPU Usage”

4. Choose “Gauge” as the visualization type

Panel 2: Memory Usage

  1. Add another panel
  2. Use this PromQL query:
100 * (1 - ((node_memory_MemFree_bytes + node_memory_Cached_bytes + node_memory_Buffers_bytes) / node_memory_MemTotal_bytes))

3. Set the panel title to “Memory Usage”

4. Choose “Gauge” as the visualization type

Panel 3: Disk Usage

  1. Add a third panel
  2. Enter this query:
100 - ((node_filesystem_avail_bytes{mountpoint="/"} * 100) / node_filesystem_size_bytes{mountpoint="/"})

3. Set the panel title to “Disk Usage”

4. Use “Gauge” for visualization

Panel 4: Network Traffic

  1. Add a fourth panel
  2. Use these queries:
rate(node_network_receive_bytes_total[5m]) rate(node_network_transmit_bytes_total[5m])

3. Set the panel title to “Network Traffic”

4. Choose “Graph” as the visualization type

Step 5: Customizing Your Dashboard

  1. Arrange your panels by dragging them into a layout you prefer
  2. Click the gear icon on each panel to adjust colors, thresholds, and other visual elements
  3. Add a title to your dashboard by clicking the gear icon next to the dashboard name

Step 6: Setting Up Refresh Interval

  1. In the top-right corner of the dashboard, click on the time range selector
  2. Choose an appropriate refresh interval (e.g., every 5m)

Conclusion

Congratulations! You’ve now created your first Grafana dashboard, visualizing key system metrics collected by Prometheus. This dashboard provides at-a-glance information about your system’s CPU, memory, disk, and network usage.From here, you can:

  • Add more panels to track other metrics
  • Set up alerting based on thresholds
  • Create different dashboards for various aspects of your system or application

Remember, effective monitoring is an iterative process. Continuously refine your dashboards based on your evolving needs and the insights you gain from your metrics.

So, whether you’re a tech enthusiast, a professional, or just someone who wants to learn more, I invite you to follow me on this journey. Subscribe to my blog and follow me on social media to stay in the loop and never miss a post.

Together, let’s explore the exciting world of technology and all it offers. I can’t wait to connect with you!”

Connect me on Social Media: https://linktr.ee/mdshamsfiroz

Happy coding!
Happy learning!

Happy monitoring!

--

--

mdshamsfiroz
mdshamsfiroz

Written by mdshamsfiroz

Trying to learn tool by putting heart inside to make something

No responses yet