- Lab
- A Cloud Guru
Collecting Linux Server Metrics with Prometheus
Prometheus uses a pull model to periodically scrape metric data from targets. In order to collect data, you will need to set up an entity that is able to provide metric data, and then configure the Prometheus server to scrape it. In this lab, you will walk through the process of configuring Prometheus monitoring for a Linux server.
Path Info
Table of Contents
-
Challenge
Install and Configure Node Exporter on the LimeDrop Web Server
-
Log in to the LimeDrop web server to perform the following steps.
-
Create a user and group that will be used to run Node Exporter:
sudo useradd -M -r -s /bin/false node_exporter
-
Download and extract the Node Exporter binary:
wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
tar xvfz node_exporter-0.18.1.linux-amd64.tar.gz
-
Copy the Node Exporter binary to the appropriate location and set ownership:
sudo cp node_exporter-0.18.1.linux-amd64/node_exporter /usr/local/bin/
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter
-
Create a
systemd
unit file for Node Exporter:sudo vi /etc/systemd/system/node_exporter.service
-
Define the Node Exporter service in the unit file:
[Unit] Description=Prometheus Node Exporter Wants=network-online.target After=network-online.target [Service] User=node_exporter Group=node_exporter Type=simple ExecStart=/usr/local/bin/node_exporter [Install] WantedBy=multi-user.target
-
Start and enable the service:
sudo systemctl daemon-reload
sudo systemctl start node_exporter
sudo systemctl enable node_exporter
-
Test that your Node Exporter is working by making a request to it from
localhost
. You should get some metric data on the screen in response to this request:curl localhost:9100/metrics
-
-
Challenge
Configure Prometheus to Scrape Metrics from the LimeDrop Web Server
-
Log in to the Prometheus server to perform the following steps.
-
Edit the Prometheus config file:
sudo vi /etc/prometheus/prometheus.yml
-
Locate the
scrape_configs
section and add a new entry under that section:... - job_name: 'LimeDrop Web Server' static_configs: - targets: ['10.0.1.102:9100'] ...
-
Restart Prometheus to load the new config:
sudo systemctl restart prometheus
-
Navigate to the Prometheus expression browser in your web browser using the public IP address of your Prometheus server:
<PROMETHEUS_SERVER_PUBLIC_IP>:9090
. -
Run the following query to verify you are able to get some metric data from the LimeDrop web server:
node_filesystem_avail_bytes{job="LimeDrop Web Server"}
-
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.