Technology

How to Set Up Monitoring Using Grafana + Prometheus

Your server is having a bad day. You just don’t know it yet. The CPU is sweating. Memory is filling up like a clogged sink. You’re blissfully unaware until the website goes poof. Panic mode. Sound familiar? It doesn’t have to be this way. Let’s talk about how to set up monitoring using Grafana + Prometheus.

This isn’t just tech jargon. It’s your early warning system. Your digital crystal ball. We’re building a dashboard that tells you exactly what’s happening, before it breaks. Imagine a car’s instrument cluster, but for your entire digital world. That’s the goal. No more flying blind.

This guide is for the doers. The folks who want to see the graphs, not just hear the theory. We’ll walk through this setup like I’m right there with you, pointing at the screen. We’ll cover the install, the configuration, the scary bits, and the glorious moment it all clicks.

You’ll learn how to set up monitoring using Grafana + Prometheus to stop problems in their tracks. Let’s get your systems talking to you.

Your Toolkit: What Are These Things, Really?

Think of Prometheus as an obsessive data collector. It’s that friend who constantly checks the weather, their stock portfolio, and the oven temperature, all at once. Its job is simple: ask your systems, “How are you feeling?” over and over.

It scrapes metrics—little numbers about CPU, memory, disk space—and stores them in its time-series database. It’s all about the “what.” What is the CPU load? What is free memory?

Grafana is the artist. The storyteller. Prometheus has all the numbers, but they’re just boring spreadsheets. Grafana takes those numbers and paints beautiful, useful graphs and dashboards. It’s your visualization powerhouse.

It answers the “so what?” You see a line spike, you know trouble is coming. Together, they’re a powerhouse duo for real-time monitoring. This isn’t about looking at yesterday’s news. It’s about seeing what’s happening right now.

  • Prometheus = The Collector. Scrapes and stores.
  • Grafana = The Storyteller. Visualizes and alerts.
  • Together = Your digital eyes and ears.
How to Set Up Monitoring Using Grafana + Prometheus

Getting Your Hands Dirty: The Installation Walkthrough

Enough talk. Let’s install. We’ll do this on a Linux server (Ubuntu is our example). It’s like setting up a new appliance. Follow the steps.

Step 1: Installing Prometheus

First, we get the collector running. Open your terminal. Feel the gentle glow of the cursor.

text

# Download the latest Prometheus. Check the website for the current version.

wget https://github.com/prometheus/prometheus/releases/download/v2.47.0/prometheus-2.47.0.linux-amd64.tar.gz

# Unpack it. Think of it as unboxing.

tar xvf prometheus-2.47.0.linux-amd64.tar.gz

# Move into the new folder.

cd prometheus-2.47.0.linux-amd64/

Now, you have the files. But we need to make it run properly, like a service that starts on boot. Let’s create a system user and move things to a tidy place.

text

# Create a user for Prometheus to run as (security first!).

sudo useradd –no-create-home –shell /bin/false prometheus

# Create needed directories.

sudo mkdir /etc/prometheus /var/lib/prometheus

# Move the config files and the main binary.

sudo cp prometheus promtool /usr/local/bin/

sudo cp -r consoles/ console_libraries/ /etc/prometheus/

sudo cp prometheus.yml /etc/prometheus/

The key file is prometheus.yml. This is the Prometheus server configuration. It’s a YAML file, so mind the spaces! It tells Prometheus what to scrape. Let’s set its permissions.

text

# Give ownership to our new user.

sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus

sudo chown prometheus:prometheus /usr/local/bin/prometheus /usr/local/bin/promtool

Finally, create a systemd service file so it runs automatically: sudo nano /etc/systemd/system/prometheus.service. Paste this:

text

[Unit]

Description=Prometheus

Wants=network-online.target

After=network-online.target

[Service]

User=prometheus

Group=prometheus

Type=simple

ExecStart=/usr/local/bin/prometheus \

    –config.file /etc/prometheus/prometheus.yml \

    –storage.tsdb.path /var/lib/prometheus/ \

    –web.console.templates=/etc/prometheus/consoles \

    –web.console.libraries=/etc/prometheus/console_libraries

[Install]

WantedBy=multi-user.target

Save and exit. Now start it!

text

sudo systemctl daemon-reload

sudo systemctl start prometheus

sudo systemctl enable prometheus

Check it’s alive: sudo systemctl status prometheus. See the green “active (running)”? Good. Open your browser, go to http://YOUR_SERVER_IP:9090. You should see the Prometheus web UI. Boom. Step one of how to set up monitoring using Grafana + Prometheus is done.

How to Set Up Monitoring Using Grafana + Prometheus

Step 2: Installing Node Exporter

Prometheus is running, but it has nothing to scrape yet. It needs an exporter—a tiny agent that translates system stats into a language Prometheus understands. The Node Exporter is the most common one for machine metrics. Let’s get it.

text

# Download Node Exporter.

wget https://github.com/prometheus/node_exporter/releases/download/v1.6.1/node_exporter-1.6.1.linux-amd64.tar.gz

# Unpack.

tar xvf node_exporter-1.6.1.linux-amd64.tar.gz

# Move the binary.

sudo cp node_exporter-1.6.1.linux-amd64/node_exporter /usr/local/bin/

sudo chown prometheus:prometheus /usr/local/bin/node_exporter

Again, make it a service: sudo nano /etc/systemd/system/node_exporter.service

text

[Unit]

Description=Node Exporter

After=network.target

[Service]

User=prometheus

Group=prometheus

Type=simple

ExecStart=/usr/local/bin/node_exporter

[Install]

WantedBy=multi-user.target

Start it.

text

sudo systemctl daemon-reload

sudo systemctl start node_exporter

sudo systemctl enable node_exporter

Check http://YOUR_SERVER_IP:9100/metrics. You should see a wall of text and numbers—that’s the raw metrics collection. Perfect. Now, we need to tell Prometheus about this new friend.

Step 3: Configuring Prometheus to Scrape

Back to the Prometheus YAML configuration. Edit it: sudo nano /etc/prometheus/prometheus.yml.

Find the scrape_configs: section. You’ll add a new job under it. Make it look like this:

yaml

scrape_configs:

  – job_name: ‘prometheus’

    static_configs:

      – targets: [‘localhost:9090’]

  – job_name: ‘node_exporter’

    static_configs:

      – targets: [‘localhost:9100’]

You just told Prometheus: “Scrape yourself on port 9090, and also scrape the Node Exporter on port 9100.” This is the core of Prometheus metrics scraping. Restart Prometheus to pick up the change: sudo systemctl restart prometheus.

Go back to the Prometheus UI (:9090). Click on Status -> Targets. You should see both prometheus and node_exporter as targets with a green “UP” state. Victory! Metrics collection with Prometheus is now working.

Bringing in the Artist: Installing and Connecting Grafana

Numbers are cool, but pictures are better. Time for Grafana.

Step 4: Installing Grafana

Grafana has an official repo. Let’s use it.

text

# Add the Grafana GPG key and repository.

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 –

# Install.

sudo apt-get update

sudo apt-get install grafana

Start it and make it run on boot.

text

sudo systemctl start grafana-server

sudo systemctl enable grafana-server

Grafana runs on port 3000. Go to http://YOUR_SERVER_IP:3000. The default login is admin / admin. It will ask you to change the password immediately. Do it. Don’t be that person.

Step 5: The Magic Handshake: Adding Prometheus as a Data Source

Inside Grafana, you’re in a blank studio. We need to connect it to your data. This is the Grafana data source configuration.

  • Hover over the gear icon (Configuration) on the left, click “Data Sources.”
  • Click “Add data source.”
  • Choose “Prometheus.”
  • In the URL field, type http://localhost:9090 (because Grafana and Prometheus are on the same server in our setup).
  • Scroll down. Click “Save & Test.”

You should see a green box: “Data source is working.” This is the moment. You’ve just connected the artist to the collector. You now know how to connect Grafana to Prometheus. This is the heart of your Grafana + Prometheus monitoring setup.

How to Set Up Monitoring Using Grafana + Prometheus

Your First Dashboard: No Art Degree Required

Dashboards sound fancy. They’re just collections of graphs. Let’s create a monitoring dashboard in Grafana from scratch.

  • Click the “+” (Create) icon on the left menu, then “Dashboard.”
  • Click “Add new panel.”
  • You’re in the panel editor. This is where you build one graph.
  • In the “Metrics” query box, you can start typing PromQL (Prometheus Query Language). Let’s start simple. Type: node_memory_MemFree_bytes. You should see a graph of free memory.
  • Want to see CPU usage? Try: rate(node_cpu_seconds_total{mode=”system”}[5m]). This calculates the per-second CPU time in system mode over 5-minute windows.
  • Play with the dropdowns. Change the graph type from “Time series” to “Stat” for a big number. Or “Gauge.”
  • When you like it, click “Apply” in the top right.

You built a panel! Click the save icon (floppy disk) to save the whole dashboard. Give it a name like “My Server Health.” Congratulations. You are now visualizing Prometheus metrics.

But who has time to build every graph? No one. Use the community’s work.

Step 6: Using Dashboard Templates (The Cheat Code)

Go back to your dashboard list. Click “+ Import” (not “New dashboard”).
In the “Import via grafana.com” box, type 1860. This is the ID for the legendary “Node Exporter Full” dashboard. It has everything.
Select your Prometheus data source from the dropdown. Click “Import.”

BAM. A complete, professional Grafana dashboard template appears. CPU, memory, disk I/O, network, temperature—every metric your server exposes, beautifully laid out. This is the fastest win in tech. Scrolling through this dashboard is like seeing your server’s soul. This is real-time monitoring using Grafana in all its glory.

Leveling Up: Alerts and Getting Fancy

A graph is a post-mortem tool if you’re not watching it 24/7. You need alerts. A nudge when things go wrong.

Setting Up Alertmanager with Prometheus

Prometheus has a sibling called Alertmanager. It handles the notifications. Installing it is similar to Prometheus itself (download, configure, run as a service). You configure routes and receivers in Alertmanager (e.g., send critical alerts to Slack, warnings to email).

Then, you define alerting rules in Prometheus. These are PromQL expressions with a condition. Like: “If the 5-minute load average is above 4 for 2 minutes, fire an alert.” It sends that alert to Alertmanager, which then pings you.

In Grafana, you can also set up alerts right on your dashboard panels. Click a panel, “Edit,” then the bell icon “Alert.” Define a rule (e.g., “when memory usage is above 90% for 5 minutes”).

You can send notifications to email, Slack, Discord, PagerDuty—endless options. Learning how to set alerts with Prometheus and Grafana transforms your setup from a history book to a proactive sentry.

Docker and Kubernetes? No Sweat.

The principles are identical. For a Docker Grafana Prometheus setup, you’d run containers: docker run -p 9090:9090 prom/prometheus. The config file lives in a mounted volume. It’s cleaner in many ways.

Kubernetes monitoring with Prometheus is its own deep dive, often using the Prometheus Operator, which automates a ton of the setup. It’s the standard for watching your containers in the cloud. The same Grafana dashboards work, they just show pod memory instead of system memory.

The Payoff: Why Bother With All This?

I once spent eight frantic hours debugging a slow website. Database queries? Code? Network? Turns out, the disk was full of old log files. A simple graph would have shown the disk space plummeting for days. I learned the hard way. You don’t have to.

When you know how to set up monitoring using Grafana + Prometheus, you move from reactive to proactive. From scared to prepared. You sleep better. You make decisions based on data, not guesses. You can prove that your new code is more efficient. You can see the traffic spike coming and scale up before it hits.

It turns infrastructure from a mysterious black box into something you can see, understand, and control. That’s power.

Wrapping It Up: Your Monitoring Journey Starts Now

So, you’ve done it. You’ve seen the path. From installing the pieces, connecting them, to building your first glorious dashboard. You now understand how to set up monitoring using Grafana + Prometheus. It’s not magic. It’s just tools, configured with a bit of patience.

Start simple. Monitor one server. Get the Node Exporter dashboard imported. Watch it for a day. See the daily rhythms of your system. Then add an alert. Then maybe monitor your database or web server with another exporter. Grow it organically.

The goal isn’t a thousand flashing graphs. The goal is one clear signal that tells you, “Hey, look at this,” before your users ever notice. Go build that. Your future, less-stressed self will thank you.


FAQs: How to Set Up Monitoring Using Grafana + Prometheus

Do Grafana and Prometheus have to be on the same server?
No, they don’t. Prometheus can scrape metrics from any server it can reach over the network. Grafana just needs a network connection to your Prometheus server’s API. You can have one central Prometheus and Grafana instance monitoring many machines.

What are the best exporters to use with Prometheus?
Start with Node Exporter for machine stats. Then, look for exporters for your specific software: mysqld_exporter for MySQL, postgres_exporter for PostgreSQL, nginx-vts-exporter for Nginx, and blackbox_exporter for probing HTTP/HTTPS endpoints (is my website up?).

I’m getting a “connection refused” error when adding the Prometheus data source. Help!
This is a classic troubleshooting Prometheus scraping issues starting point. It means Grafana can’t talk to Prometheus. Check: 1) Is Prometheus running? (sudo systemctl status prometheus). 2) Is the firewall on your server blocking port 9090? 3) Did you use the correct URL (e.g., http://localhost:9090 if on the same server)?

How do I write my own PromQL queries?
Start by browsing the metrics Prometheus is collecting. Go to its web UI (:9090), click on “Graph,” and use the dropdown next to the “Execute” button to see a list. Queries often use functions like rate() for counters or avg_over_time() for smoothing. The Prometheus documentation is your best friend here.

Is this setup good for cloud monitoring using Grafana?
Absolutely. The principles are the same. You can run Prometheus and Grafana in the cloud (on a VM, in containers, or as managed services). You can also use Prometheus to scrape metrics from cloud provider APIs (AWS CloudWatch, Google Cloud Monitoring) using specific exporters, letting Grafana visualize everything in one place.

References:

Read More: How to Optimize Backend API Performance

George Thomas

At , George Thomas our authors are passionate writers and bloggers who share fresh, helpful insights across topics like news, lifestyle, tech, fashion, and more. With unique voices and real experience, we aim to keep you informed, inspired, and entertained with every post.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button