How to Set Up a Monitoring System with Prometheus: A Step-by-Step Guide
Prometheus is an open-source monitoring and alerting toolkit designed for reliability and scalability. Its pull model collects time-series data from configured endpoints, making it ideal for dynamic cloud environments. This tutorial walks through a basic Prometheus setup with node_exporter and Grafana.
Before starting, ensure you have a Linux server (Ubuntu 20.04+ used here), root access, and a basic understanding of terminal commands. You’ll also need port 9090 open for Prometheus and port 3000 for Grafana.
Install and Configure Prometheus
Download the latest Prometheus release:
- Visit
https://prometheus.io/download/and grab thelinux-amd64tarball - Extract it:
tar xvf prometheus-*.tar.gz - Edit
prometheus.ymlto define scrape targets. Default config already scrapes Prometheus itself on port 9090 - Run Prometheus:
./prometheus --config.file=prometheus.yml
Verify it’s running by visiting http://your-server-ip:9090 — the expression browser should load.
Add Node Exporter for System Metrics
Node exporter exposes hardware and OS metrics. Install it on the same or another machine:
- Download and extract node_exporter similarly from the Prometheus downloads page
- Run it:
./node_exporter(listens on port 9100 by default) - Add it to
prometheus.ymlunderscrape_configs:
- job_name: 'node_exporter'
static_configs:
- targets: ['localhost:9100']
Restart Prometheus and check the targets page (/targets) — should show “UP”.
Visualize Metrics with Grafana
Grafana connects to Prometheus for dashboards. Install Grafana:
- Follow official APT installation for your distro, then start with
sudo systemctl start grafana-server - Access
http://your-server-ip:3000, login (admin/admin), add a Prometheus data source pointing tohttp://localhost:9090 - Import a pre-built dashboard (e.g., Node Exporter Full ID 1860) for instant system monitoring
Set Up Basic Alerting (Optional)
Alertmanager handles alerts. Install and configure alertmanager.yml with a receiver (email, Slack). Define alert rules in Prometheus config rule_files. Test with a simple rule like high CPU usage.
Your monitoring system is now live. Explore PromQL for custom queries and add more exporters (e.g., blackbox_exporter for endpoints). Regularly update and tune retention settings.