Prometheus
Placeholder text.
Installing Prometheus
Downloading The Package
You may need to check the Prometheus documentation/downloads for the latest version here.
Copy the URL for the version you need from that page (should be a Github link) and paste it into the below:
wget INSERT_LINK_HERE
Extracting The Package
Extract the file:
tar xfvz prometheus-WHATEVER-VERSION-YOU-HAVE.tar.gz
Creating Prometheus User
Create a user account for Prometheus, without a home folder and with a nologin shell:
sudo useradd --no-create-home --shell /usr/sbin/nologin prometheus
Create Prometheus Directories
Create The Directories
Create the below directories:
sudo mkdir -p /etc/prometheus /var/lib/prometheus
Relocate The Directories/Files
Copy the two files below, from within the 'prometheus-WHATEVER-VERSION-YOU-HAVE' directory, to '/usr/local/bin/'
sudo cp prometheus /usr/local/bin/ sudo cp promtool /usr/local/bin/
Copy the below directories, again from within the 'prometheus-WHATEVER-VERSION-YOU-HAVE' directory, to the '/etc/prometheus/' directory:
sudo cp -r consoles/ /etc/prometheus/ sudo cp -r console_libraries/ /etc/prometheus/
Then we need to move the provided .yml file for prometheus to the 'etc/prometheus/' directory:
sudo cp prometheus.yml /etc/prometheus/prometheus.yml
Changing Ownership Of The Files
Change ownership of the files to the prometheus user we created:
sudo chown prometheus:prometheus /usr/local/bin/prometheus sudo chown prometheus:prometheus /usr/local/bin/promtool
sudo chown -R prometheus:prometheus /etc/prometheus sudo chown -R prometheus:prometheus /var/lib/prometheus
Create Systemd Service for Prometheus
Creating Systemd Service File
Create the service file itself:
sudo vim /etc/systemd/system/prometheus.service
Include the following:
[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 \
--storage.tsdb.retention.time=15d \
--web.enable-lifecycle \ # Each line requires a trailing \ EXCEPT the last line of the ExecStart block
--web.listen-address=:PORT # Uses 9090 by default if web.listen-address is not provided, can use a different port if specified here
[Install]
Wantedby=multi-user.target
Starting The Service
Once the service file is created and all the files/directories are where they should be, the Prometheus service can be started:
#Reload the daemons sudo systemctl daemon-reload #Start the prometheus service sudo systemctl start prometheus #Check the status of Prometheus sudo systemctl status prometheus #If the service starts successfully, enable the service to start on every boot sudo systemctl enable prometheus
Then we can verify that Prometheus is running and listening on the specified port:
curl http://localhost:PORT/-/healthy
If it is working properly, the output should look like:
Prometheus Server is Healthy
Configure Prometheus
File Location
Configuring Prometheus requires the editing of the '/etc/prometheus/prometheus.yml' file.
Example File
Below is a basic config file for Prometheus:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:PROMETHEUS_PORT']
Indentation and formatting is CRUCIAL in this file, triple check everything is correct.
You can also run the promtool utility to verify via:
promtool check config /etc/prometheus/prometheus.yml
If you additionally use the node exporter, more info here, include the below with it's job name and port number as well.
- job_name: 'node_exporter'
static_configs:
- targets: ['localhost:NODE_PORT']
When the config file is updated, update Prometheus via:
curl -X POST http://localhost:PORT/-/reload