In this guide, we are going to learn how to install Prometheus on Debian 10. Prometheus is an open-source systems and service monitoring system. It collects metrics from configured targets via HTTP calls at given intervals, evaluates rule expressions, displays the results, and can trigger alerts if some conditions are met.
Table of Contents
Installing Prometheus on Debian 10
Prometheus is made up various components;
- The main Prometheus server which scrapes and stores time series data
- Client libraries for instrumenting application code
- Push gateway for supporting short-lived jobs
- Exporters for exporting existing metrics from third-party systems as Prometheus metrics in cases where it is not feasible to instrument a given system with Prometheus metrics directly for example in services like HAProxy, StatsD, Graphite, etc.
- Alertmanager to handle alerts.
Prometheus Releases
Prometheus and its other components are available on the default Debian 10 repositories. However, the available versions may not be up-to-date. You can verify the available versions by running the command below;
apt-cache policy prometheus
prometheus:
Installed: (none)
Candidate: 2.42.0+ds-5+b5
Version table:
2.42.0+ds-5+b5 500
500 http://deb.debian.org/debian buster/main amd64 Packages
The current release as of this writing is v2.47.0, hence the package from default Debian repos is a bit old.
Install Prometheus Using Pre-compiled Binaries on Debian 10
To ensure that you got the latest versions of Prometheus installed, you can use the pre-compiled binaries.
Create Prometheus System User and Group
Before you can begin the installation, you have to create Prometheus system user and group as shown below;
useradd -M -r -s /bin/false prometheus
Create Prometheus Directories
Next, you need to create the directories that will be used to store Prometheus configurations files and other data.
mkdir /etc/prometheus /var/lib/prometheus
Download Prometheus Binary
Next, navigate to the downloads section and grab the latest version of Prometheus on the downloads section. You simply use wget to download it.
Replace the value of the VER variable with the current release version.
VER=2.47.0
wget https://github.com/prometheus/prometheus/releases/download/v$VER/prometheus-$VER.linux-amd64.tar.gz
Install Prometheus
Once you have downloaded the binary, extract it and proceed to install it as follows.
tar xzf prometheus-$VER.linux-amd64.tar.gz
Next, copy the prometheus and promtool binaries under the extracted archive folder to /usr/local/bin
directory.
cp prometheus-$VER.linux-amd64/{prometheus,promtool} /usr/local/bin/
After copying, set the user and group ownership of these binaries to prometheus.
chown prometheus:prometheus /usr/local/bin/{prometheus,promtool}
Next, copy the consoles
and console_libraries
directories to /etc/prometheus
.
cp -r prometheus-$VER.linux-amd64/{consoles,console_libraries} /etc/prometheus/
Create Prometheus Configuration file
The default Prometheus configuration file is located on the extracted archive folder. For the demonstration purposes, we will just copy it to Prometheus configuration directory and modify it as follows;
cp prometheus-$VER.linux-amd64/prometheus.yml /etc/prometheus/
In the default configuration there is a single job, called prometheus , which scrapes the time series data exposed by the Prometheus server. The job contains a single, statically configured, target, the localhost on port 9090.
See the sample configuration contents;
cat /etc/prometheus/prometheus.yml
# my global config
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_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
Update Ownership of Prometheus Configurations
Next, set the user and group ownership of Prometheus configuration directory, /etc/prometheus to prometheus.
chown -R prometheus:prometheus /etc/prometheus
Once that is done, similarly set the user and group ownership of Prometheus data directory, /var/lib/prometheus/ to prometheus.
chown -R prometheus:prometheus /var/lib/prometheus
Running Prometheus on Debian 10
At the very least, Prometheus is now set and is ready to run. However, at this point we do not have the Prometheus service configuration file and hence, we can run it in standalone mode by executing the command below;
prometheus --config.file=/etc/prometheus/prometheus.yml
ts=2023-10-04T04:55:48.249Z caller=main.go:539 level=info msg="No time or size retention was set so using the default time retention" duration=15d
ts=2023-10-04T04:55:48.249Z caller=main.go:583 level=info msg="Starting Prometheus Server" mode=server version="(version=2.47.0, branch=HEAD, revision=efa34a5840661c29c2e362efa76bc3a70dccb335)"
ts=2023-10-04T04:55:48.250Z caller=main.go:588 level=info build_context="(go=go1.21.0, platform=linux/amd64, user=root@409eb5e6b30c, date=20230906-10:20:07, tags=netgo,builtinassets,stringlabels)"
ts=2023-10-04T04:55:48.250Z caller=main.go:589 level=info host_details="(Linux 6.1.0-11-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.38-4 (2023-08-08) x86_64 debian (none))"
ts=2023-10-04T04:55:48.250Z caller=main.go:590 level=info fd_limits="(soft=1048576, hard=1048576)"
ts=2023-10-04T04:55:48.251Z caller=main.go:591 level=info vm_limits="(soft=unlimited, hard=unlimited)"
ts=2023-10-04T04:55:48.252Z caller=web.go:566 level=info component=web msg="Start listening for connections" address=0.0.0.0:9090
ts=2023-10-04T04:55:48.252Z caller=main.go:1024 level=info msg="Starting TSDB ..."
ts=2023-10-04T04:55:48.261Z caller=tls_config.go:274 level=info component=web msg="Listening on" address=[::]:9090
ts=2023-10-04T04:55:48.261Z caller=tls_config.go:277 level=info component=web msg="TLS is disabled." http2=false address=[::]:9090
ts=2023-10-04T04:55:48.262Z caller=head.go:600 level=info component=tsdb msg="Replaying on-disk memory mappable chunks if any"
ts=2023-10-04T04:55:48.262Z caller=head.go:681 level=info component=tsdb msg="On-disk memory mappable chunks replay completed" duration=1.675µs
ts=2023-10-04T04:55:48.262Z caller=head.go:689 level=info component=tsdb msg="Replaying WAL, this may take a while"
ts=2023-10-04T04:55:48.263Z caller=head.go:760 level=info component=tsdb msg="WAL segment loaded" segment=0 maxSegment=0
ts=2023-10-04T04:55:48.263Z caller=head.go:797 level=info component=tsdb msg="WAL replay completed" checkpoint_replay_duration=40.185µs wal_replay_duration=454.197µs wbl_replay_duration=116ns total_replay_duration=1.473217ms
ts=2023-10-04T04:55:48.265Z caller=main.go:1045 level=info fs_type=EXT4_SUPER_MAGIC
ts=2023-10-04T04:55:48.266Z caller=main.go:1048 level=info msg="TSDB started"
ts=2023-10-04T04:55:48.266Z caller=main.go:1229 level=info msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
ts=2023-10-04T04:55:48.266Z caller=main.go:1266 level=info msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml totalDuration=717.883µs db_storage=1.014µs remote_storage=942ns web_handler=299ns query_engine=954ns scrape=111.174µs scrape_sd=14.343µs notify=19.174µs notify_sd=7.264µs rules=1.104µs tracing=3.927µs
ts=2023-10-04T04:55:48.267Z caller=main.go:1009 level=info msg="Server is ready to receive web requests."
ts=2023-10-04T04:55:48.267Z caller=manager.go:1009 level=info component="rule manager" msg="Starting rule manager..."
By default, it will be listening on port 9090/TCP. Open another terminal and confirm;
ss -altnp
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 4096 *:9090 *:*
You can stop the process above by pressing CTRL+C.
Create Prometheus Systemd Service File
To be able to run prometheus as a service, you can create a systemd service configuration file as shown below;
cat > /etc/systemd/system/prometheus.service << 'EOF'
[Unit]
Description=Prometheus Time Series Collection and Processing Server
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
EOF
Next, reload systemd configuration files;
systemctl daemon-reload
Start and enable Prometheus to run on system boot.
systemctl enable --now prometheus
To check the status of Prometheus service;
systemctl status prometheus
● prometheus.service - Prometheus Time Series Collection and Processing Server
Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; preset: enabled)
Active: active (running) since Wed 2023-10-04 01:00:45 EDT; 31s ago
Main PID: 3799 (prometheus)
Tasks: 6 (limit: 2304)
Memory: 20.2M
CPU: 68ms
CGroup: /system.slice/prometheus.service
└─3799 /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/>
Oct 04 01:00:45 debian prometheus[3799]: ts=2023-10-04T05:00:45.995Z caller=tls_config.go:274 level=info component=web msg="Listening on" address=[::]:9090
Oct 04 01:00:45 debian prometheus[3799]: ts=2023-10-04T05:00:45.995Z caller=tls_config.go:277 level=info component=web msg="TLS is disabled." http2=false address=[::]:9090
Oct 04 01:00:45 debian prometheus[3799]: ts=2023-10-04T05:00:45.995Z caller=head.go:760 level=info component=tsdb msg="WAL segment loaded" segment=0 maxSegment=0
Oct 04 01:00:45 debian prometheus[3799]: ts=2023-10-04T05:00:45.995Z caller=head.go:797 level=info component=tsdb msg="WAL replay completed" checkpoint_replay_duration=23.504µs wal_replay_duration=1.536714ms wb>
Oct 04 01:00:45 debian prometheus[3799]: ts=2023-10-04T05:00:45.999Z caller=main.go:1045 level=info fs_type=EXT4_SUPER_MAGIC
Oct 04 01:00:45 debian prometheus[3799]: ts=2023-10-04T05:00:45.999Z caller=main.go:1048 level=info msg="TSDB started"
Oct 04 01:00:45 debian prometheus[3799]: ts=2023-10-04T05:00:45.999Z caller=main.go:1229 level=info msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml
Oct 04 01:00:45 debian prometheus[3799]: ts=2023-10-04T05:00:45.999Z caller=main.go:1266 level=info msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml totalDuration=313.352µs >
Oct 04 01:00:45 debian prometheus[3799]: ts=2023-10-04T05:00:45.999Z caller=main.go:1009 level=info msg="Server is ready to receive web requests."
Oct 04 01:00:45 debian prometheus[3799]: ts=2023-10-04T05:00:45.999Z caller=manager.go:1009 level=info component="rule manager" msg="Starting rule manager..."
Access Prometheus Web Interface
You can now access Prometheus using the address, http://<server_IP>:9090. This will take you to Prometheus’s built-in expression browser.
The scraped metrics can be viewed under, http://<server_IP>:9090/metrics.
To check the status of your node, navigate to Status > Targets.
Want to learn how to monitor Linux hosts with Prometheus Node Exporter? Check the link below;
Integrate Prometheus with Grafana for Monitoring
Monitor Linux System Metrics with Prometheus Node Exporter