Smart Monitoring with Prometheus & Grafana

Grafana is an open-source analytics and visualization platform that connects to data sources, such as Prometheus, to create dashboards, alerts, and visualize real-time performance metrics.

Prometheus is an open-source monitoring and alerting toolkit that collects time-series metrics from targets like Node Exporter, stores them locally, supports PromQL for querying, and integrates with tools like Grafana for visualization

Node Exporter is a Prometheus exporter that exposes hardware and operating system metrics, including CPU usage, memory, disk and filesystem statistics, network I/O, and system load.

Prerequisite

  • Ensure that the Grafana server is up and running. If it's not, refer to this article

Now, set up Prometheus and Node Exporter on another node and visualize the data on the Grafana dashboard.

Create a Prometheus System User

Prometheus should run as a non-login system user:

sudo useradd --system --no-create-home --shell /bin/false Prometheus

Then create a directory

sudo mkdir prometheus

Download and install the Prometheus

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

Extract Prometheus files, move them, and create directories:

tar -xvf prometheus-2.47.1.linux-amd64.tar.gz
cd prometheus-2.47.1.linux-amd64/
sudo mkdir -p /data /etc/prometheus
sudo mv prometheus promtool /usr/local/bin/
sudo mv consoles/ console_libraries/ /etc/prometheus/
sudo mv prometheus.yml /etc/prometheus/prometheus.yml

Ensure Prometheus owns its files:

Create a systemd unit configuration file for Prometheus:

Reload systemd and restart the service:

You can access Prometheus in a web browser using your server’s IP and port 9090

Install Node Exporter

Create User

Create a directory

Download and install the Node-Exporter

Extract Prometheus files, move them, and create directories:

Create a systemd unit configuration file for Node-exporter

Reload systemd and restart the service:

You can access Node exporter in a web browser using your server’s IP and port 9100

Prometheus Configuration:

To install Grafana, follow this link.

Now open the Grafana dashboard

Add Prometheus Data Source:

To visualize metrics, you need to add a data source. Follow these steps:

Click on the Add new data source

Now select the Prometheus

Set the name of your server, enter your worker's IP address with the corresponding port, and then click Save and Test.

Now, go back to the dashboard section and add a new dashboard.

For the node exporter ID, navigate to the node exporter website

We are using the ID:- 1860

To import a dashboard, fill in the details such as the server name, select the dashboard folder, enter the UID, and choose Prometheus as the data source type. Click on the import

After clicking on the final import.

Now you can see the data is visible.

Last updated