In this tutorial, we'll be setting up Prometheus, an open-source system monitoring and alerting toolkit. Our goal is to install and configure Prometheus on a server and use it for system monitoring.
By the end of this tutorial, you will learn:
- What is Prometheus
- How to install and configure Prometheus
- How to use Prometheus for system monitoring
Prerequisites:
Before you start, ensure you have the following:
- A server running Ubuntu 18.04 or higher
- Basic knowledge of Linux commands
- Basic understanding of system monitoring
Step 1: Update the packages list
sudo apt-get update
Step 2: Download the latest release of Prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.26.0/prometheus-2.26.0.linux-amd64.tar.gz
Step 3: Extract the downloaded tar file
tar xvf prometheus-2.26.0.linux-amd64.tar.gz
Step 4: Navigate to the extracted directory
cd prometheus-2.26.0.linux-amd64
Step 5: Open the configuration file using a text editor
nano prometheus.yml
This file is where you define what you want to monitor and how. Make the necessary configurations based on your system’s requirements.
Step 6: Start Prometheus with the configuration file
./prometheus --config.file=prometheus.yml
Prometheus is now running and starts scraping data based on the configurations.
Example 1: A basic prometheus.yml
configuration
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
In the above example, scrape_interval
is how often Prometheus will scrape targets for metrics, and evaluation_interval
is how often the software will evaluate rules. The job_name
is an arbitrary name given to a certain instance of a job. targets
list is the list of endpoints Prometheus will hit to scrape metrics.
Expected Output
Upon running Prometheus with this configuration, it will start scraping metrics from the target URL localhost:9090
every 15 seconds.
We've covered how to install, configure and run Prometheus for system monitoring.
To further your learning, you can explore:
- How to use Prometheus with Grafana for visualizing data
- How to set up alerting with Prometheus
Additional resources:
- Prometheus Official Documentation
- Prometheus GitHub
Exercise 1: Install Prometheus on your local machine and configure it to scrape metrics from a local application.
Exercise 2: Configure Prometheus to scrape metrics from two different applications running on different ports.
Exercise 3: Set up a Grafana dashboard and visualize the metrics being scraped by Prometheus.
Tips for further practice: Try to set up alerting rules for your metrics and learn how to use Prometheus Query Language (PromQL) to query your metrics.