Feedback

Chat Icon

Observability with Prometheus and Grafana

A Complete Hands-On Guide to Operational Clarity in Cloud-Native Systems

Exploring Prometheus: Installation and Configuration
19%

Installing Prometheus

In this section, we are going to learn how to install Prometheus. The process is straightforward.

Prometheus is built as a single statically linked binary, which means that you don't need to install its dependencies manually. These dependencies are compiled directly into the binary at build time. For example:

  • go-tsz: A time series compression algorithm from Facebook's Gorilla paper.
  • LevelDB: A key-value storage library written by Google that provides an ordered mapping from string keys to string values.
  • Snappy: A fast compressor/decompressor developed by Google that does not aim for maximum compression, but for very high speeds.

Some tools used by Prometheus

Some tools used by Prometheus

Let's proceed with the installation. You can download the latest stable version of Prometheus from the download page. We are going to use version 3.7.2 for this guide. These are the steps you need to execute:

url=https://github.com/prometheus/prometheus/releases/download/v3.7.2/prometheus-3.7.2.linux-amd64.tar.gz
cd $(mktemp -d) && wget $url
tar -xvf prometheus-3.7.2.linux-amd64.tar.gz
cd prometheus-3.7.2.linux-amd64

You can change the URL to use a different version, but I recommend using the same version to stay consistent with the examples in this course. Next, you can test that Prometheus is working by executing the following command:

./prometheus

If everything is working correctly, you can stop the process by pressing CTRL+C.

A better way to run Prometheus is to set it up as a systemd service and run it in the background as a daemon with a dedicated user. This way, we can manage Prometheus as a service. Let's start by creating a new user and group for Prometheus:

# Create a new user and group for Prometheus
useradd \
--no-create-home \
--shell /bin/false \
prometheus

# Verify that the user has been created
id prometheus

Create the necessary directories for Prometheus configuration and data:

mkdir -p /etc/prometheus
mkdir -p /var/lib/prometheus

Change the ownership of the directories to prometheus:

chown prometheus:prometheus /etc/prometheus
chown prometheus:prometheus /var/lib/prometheus

Copy the Prometheus binaries to /usr/local/bin. These binaries are needed to start and use Prometheus:

cp prometheus /usr/local/bin/
cp promtool /usr/local/bin/

Change the ownership of these binaries to the prometheus user:

chown prometheus:prometheus /usr/local/bin/prometheus
chown prometheus:prometheus /usr/local/bin/promtool

Observability with Prometheus and Grafana

A Complete Hands-On Guide to Operational Clarity in Cloud-Native Systems

Enroll now to unlock all content and receive all future updates for free.