Introduction
Prometheus is an open-source monitoring system developed by SoundCloud. Development on Prometheus started back in 2012 when SoundCloud felt that the existing monitoring systems were proving insufficient for their needs. It uses a time-series database just like Druid, InfluxDB, Graphite.
However, Prometheus is able to work on a multi-dimensional data model, uses a powerful query to language to leverage this data model properly. Uses pull method over HTTP to record real-time metrics, this helps admins to easily fine-tune the capabilities to their needs which in turn produces more accurate reports.
Prometheus has a browser-based tool called PromDash to build and view dashboards that use SQL backend. The Data model stores all data as time series: streams of timestamped values belonging to the same metric and the same set of labeled dimensions.
Another main attraction of Prometheus is that it uses single server nodes that are autonomous. How many times have you just given up trying to configure a distributed system cluster? Well, that wonโt be the case this time.
Prerequisite:
To follow this tutorial, you will need:
- sudo access to your system.
- Working internet connection as we will download the Prometheus Linux Binary.
Setup Prometheus Binaries
Step 1: Updating repos
As always, our first step will be to update the yum package repositories.
yum update -y
Step 2: Creating user and directories
Letโs create a Prometheus user, required directories, and make prometheus user as the owner of those directories.
useradd –no-create-home –shell /bin/false prometheus
mkdir /etc/prometheus
mkdir /var/lib/prometheus
chown prometheus:prometheus /etc/prometheus
chown prometheus:prometheus /var/lib/prometheus
Step 3: Getting Prometheus
Go to the official Prometheus downloads page and get the download link for Linux binary by right-clicking the binary and clicking on Copy Link next.
Step 4: Downloading and Installing Prometheus
Download the source using wget, untar it, and rename the extracted folder to prometheus-files.
wget https://github.com/prometheus/prometheus/releases/download/v2.20.0-rc.1/prometheus-2.20.0-rc.1.linux-amd64.tar.gz
tar -xvf prometheus-2.20.0-rc.1.linux-amd64.tar.gz
mv prometheus-2.20.0-rc.1.linux-amd64 prometheus-files
Step 5: Copying prometheus and promtool
You will have to copy prometheus and promtool binary from prometheus-files folder to /usr/local/bin.
cp prometheus-files/prometheus /usr/local/bin/
cp prometheus-files/promtool /usr/local/bin/
Step 6: Changing ownership
Change the ownership to prometheus user.
chown prometheus:prometheus /usr/local/bin/prometheus
chown prometheus:prometheus /usr/local/bin/promtool
Step 7: Moving consoles and libraries
Move the consoles and console_libraries directories from prometheus-files to /etc/prometheus folder and change the ownership to prometheus user.
cp -r prometheus-files/consoles /etc/prometheus
cp -r prometheus-files/console_libraries /etc/prometheus
chown -R prometheus:prometheus /etc/prometheus/consoles
chown -R prometheus:prometheus /etc/prometheus/console_libraries
Setup Prometheus Configuration
prometheus.yml holds all the prometheus configurations. The file be present in /etc/prometheus/prometheus.yml file.
Step 1: Create prometheus.yml file.
Create the prometheus.yml file.
touch /etc/prometheus/prometheus.yml
Step 2: Edit prometheus.yml file.
Open the file using vim or any file editor of your liking and copy the following contents to the prometheus.yml file.
global:
scrape_interval: 10s
scrape_configs:
– job_name: ‘prometheus’
scrape_interval: 5s
static_configs:
– targets: [‘localhost:9090’]
Step 3: Ownership change for prometheus.yml file.
Change the ownership of the file to prometheus user.
chown prometheus:prometheus /etc/prometheus/prometheus.yml
Setup Prometheus Service File
Step 1: Create a prometheus service file.
vi /etc/systemd/system/prometheus.service
Step 2: Edit prometheus.service
Copy the following content to the file.
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/bin/prometheus \
–config.file /etc/prometheus/prometheus.yml \
–storage.tsdb.path /var/lib/prometheus/ \
–web.console.templates=/etc/prometheus/consoles \
–web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
Step 3: Reload the systemd
Reload the systemd service to register the prometheus service and start the prometheus service.
systemctl daemon-reload
systemctl start prometheus
Check the prometheus service status using the following command.
systemctl status prometheus
The status should show the active state as shown below.
Access Prometheus Web UI
Now you will be able to access the prometheus UI on 9090 port of the prometheus server.
http://<prometheus-ip>:9090/graph
You should be able to see the following UI as shown below.
Currently, we have only configured Prometheus. We need to register a target to actually some metrics from the system.
In order to do this please follow along to the next tutorial: Prometheus Node Exporter Guide
2 Comments
How To Monitor Linux Servers Using Prometheus Node Exporter – Virtono Community · July 28, 2020 at 1:31 PM
[…] Prometheus Server: In order to use the Prometheus Node Exporter you need a Prometheus Server running, please see the Prometheus setup guide for Linux. […]
How To Integrate and Visualize Prometheus Metrics In Grafana – Virtono Community · July 29, 2020 at 1:31 PM
[…] Setup Prometheus on Linux […]