Introduction

Grafana is a leading time-series, an open-source platform for visualization and monitoring. It allows you to query, visualize, set alerts, and understand metrics no matter where they are stored. You can create amazing dashboards in Grafana to visualize and monitor the metrics.

Prometheus is an open-source time-series monitoring system for machine-centric and highly dynamic service-oriented architectures. It can literally monitor everything. It integrates with Grafana very smoothly as Grafana also offers Prometheus as one of its data sources. If you are a newbie, I would suggest checking out an introduction to Prometheus and Grafana article. Let me show you how to install them on CentOS. You should have at least 2GB of RAM. You can get a cloud server from DigitalOcean to try out.

Installing Prometheus

Step 1: Download Prometheus

Download the latest Prometheus Linux package from the official page. Extract the package which you downloaded.

Step 2: Configure Prometheus

Create a new user Prometheus using the below command. Give all the Prometheus file ownership to Prometheus user. Make all the files executable in the path mentioned. It is time to configure Prometheus as a service inside the systemd. Create a file prometheus.service and put the lines mentioned below in the file and save it.

Step 3: Start Prometheus

Using systemctl, reload the systemd system, and start the Prometheus service. Its status should show the service is running if you have followed all the steps correctly.

Step 4: Access Prometheus Web UI

Open the browser and access to server’s IP with port 9090 to access the web interface of Prometheus. Go to Status»Targets to see what all and where Prometheus is currently running.

Installing Grafana

Step 1: Add Grafana Repo

By default, the Grafana repository is not present in CentOS repositories, so you need to add it. Create a file grafana.repo inside /etc/yum.repos.d/ and add the lines mentioned below.

Step 2: Install Grafana

Update CentOS and install the Grafana package.

Step 3: Start Grafana

Start grafana server and check the status if its running or not.

Step 4: Access Grafana Web UI

Once the service is up and running, access to server’s IP with port 3000 to access the web interface of Grafana. For the first time, you need to use admin as bother username and password; then you will be asked to set your own password. This is how the Home of Grafana looks like.

Installing Node Exporter

node_exporter is an official package that should be installed on Linux servers to be monitored. It exposes multiple hardware and OS metrics, which will be pulled by Prometheus and eventually visualized on Grafana.

Step 1: Download Node Exporter

Use wget to download the node exporter package on your server. Extract the downloaded file.

Step 2: Configure Node Exporter

It is time to configure Node Exporter as a service inside systemd. Create a file node_exporter.service and put the lines mentioned below in the file and save it.

Step 3: Start Node Exporter

Adding Server to Prometheus

Step 1: Edit prometheus.yml

You need to add a new job in the prometheus.yml file. Open a new tab in the terminal and edit the file as mentioned below. Note: Above, I have configured the localhost in the target as I would like to monitor the Prometheus server itself. You can change this to the actual Linux server’s IP. Port 9100 is the default port of node_exporter.

Step 2: Stop and Start Prometheus

Step 3: Check Targets

Go to https://localhost:9090/targets; you will find targets running, one will be node exporter.

Integrating Prometheus to Grafana

Now that Grafana and Prometheus are installed. let us use them for monitoring servers.

Go to Grafana home and click on the setting sign on the left. Then click on “Data Sources”. Click on Add data source and select Prometheus.

Set the URL as Prometheus server’s IP with port 9090. In this example, I am running Prometheus and Grafana on the same server so it would be http://localhost:9090 Click on Save & Test. You will get a success message of data source getting added.

Great! Grafana is successfully connected to Prometheus. Its time to create a dashboard. To make it easy,  I will use the existing node exporter dashboard, which is present on Grafana’s official website to monitor Linux server metrics.

Go to the Grafana home dashboard, click on + sign and click on Import. In Import via grafana.com, put the dashboard id 1860 and click on Load.

Then select the Prometheus data source and click on Import.

The complete node exporter dashboard will get imported. You can see all the metrics like system load, ram used, CPU busy, etc. are getting monitored on Grafana successfully.

If you scroll down, you can see Grafana is able to visualize plenty of metrics.

If you want to get more information, you can click on the particular metric visualization and look at it in detail. Here, I am checking Network Traffic by Packets visualization for the last 30 minutes.

Conclusion I hope this gives you an idea of how to set up Grafana and Prometheus for server metrics. There are more ways to monitor servers – you can try cloud-based server monitoring or self-hosted lightweight software. If you are interested in learning Grafana, then I would suggest checking out this Udemy hands-on course.

A Guide to Monitor Linux Server using Prometheus and Grafana - 76A Guide to Monitor Linux Server using Prometheus and Grafana - 48A Guide to Monitor Linux Server using Prometheus and Grafana - 22A Guide to Monitor Linux Server using Prometheus and Grafana - 57A Guide to Monitor Linux Server using Prometheus and Grafana - 75A Guide to Monitor Linux Server using Prometheus and Grafana - 93A Guide to Monitor Linux Server using Prometheus and Grafana - 39A Guide to Monitor Linux Server using Prometheus and Grafana - 24A Guide to Monitor Linux Server using Prometheus and Grafana - 74A Guide to Monitor Linux Server using Prometheus and Grafana - 60A Guide to Monitor Linux Server using Prometheus and Grafana - 45A Guide to Monitor Linux Server using Prometheus and Grafana - 29A Guide to Monitor Linux Server using Prometheus and Grafana - 88A Guide to Monitor Linux Server using Prometheus and Grafana - 75A Guide to Monitor Linux Server using Prometheus and Grafana - 24A Guide to Monitor Linux Server using Prometheus and Grafana - 25A Guide to Monitor Linux Server using Prometheus and Grafana - 31A Guide to Monitor Linux Server using Prometheus and Grafana - 75A Guide to Monitor Linux Server using Prometheus and Grafana - 20A Guide to Monitor Linux Server using Prometheus and Grafana - 15A Guide to Monitor Linux Server using Prometheus and Grafana - 15A Guide to Monitor Linux Server using Prometheus and Grafana - 11A Guide to Monitor Linux Server using Prometheus and Grafana - 56A Guide to Monitor Linux Server using Prometheus and Grafana - 1A Guide to Monitor Linux Server using Prometheus and Grafana - 35A Guide to Monitor Linux Server using Prometheus and Grafana - 44A Guide to Monitor Linux Server using Prometheus and Grafana - 40A Guide to Monitor Linux Server using Prometheus and Grafana - 95A Guide to Monitor Linux Server using Prometheus and Grafana - 75A Guide to Monitor Linux Server using Prometheus and Grafana - 95A Guide to Monitor Linux Server using Prometheus and Grafana - 85A Guide to Monitor Linux Server using Prometheus and Grafana - 2A Guide to Monitor Linux Server using Prometheus and Grafana - 48A Guide to Monitor Linux Server using Prometheus and Grafana - 27A Guide to Monitor Linux Server using Prometheus and Grafana - 26A Guide to Monitor Linux Server using Prometheus and Grafana - 96