Difference between revisions of "Prometheus"
| Line 1: | Line 1: | ||
Placeholder text. | Placeholder text. | ||
| − | =Prometheus= | + | =Installing Prometheus= |
| − | + | ==Downloading The Package== | |
| − | |||
| − | |||
| − | |||
You may need to check the Prometheus documentation/downloads for the latest version [https://prometheus.io/download/ here.] | You may need to check the Prometheus documentation/downloads for the latest version [https://prometheus.io/download/ here.] | ||
| Line 12: | Line 9: | ||
<nowiki>wget INSERT_LINK_HERE</nowiki> | <nowiki>wget INSERT_LINK_HERE</nowiki> | ||
| − | + | ==Extracting The Package== | |
Extract the file: | Extract the file: | ||
<nowiki>tar xfvz prometheus-WHATEVER-VERSION-YOU-HAVE.tar.gz</nowiki> | <nowiki>tar xfvz prometheus-WHATEVER-VERSION-YOU-HAVE.tar.gz</nowiki> | ||
| − | + | =Creating Prometheus User= | |
Create a user account for Prometheus, without a home folder and with a nologin shell: | Create a user account for Prometheus, without a home folder and with a nologin shell: | ||
| Line 22: | Line 19: | ||
| − | + | =Create Prometheus Directories= | |
| − | + | ==Create The Directories== | |
Create the below directories: | Create the below directories: | ||
<nowiki>sudo mkdir -p /etc/prometheus /var/lib/prometheus</nowiki> | <nowiki>sudo mkdir -p /etc/prometheus /var/lib/prometheus</nowiki> | ||
| − | + | ==Relocate The Directories/Files== | |
Copy the two files below, from within the 'prometheus-WHATEVER-VERSION-YOU-HAVE' directory, to '/usr/local/bin/' | Copy the two files below, from within the 'prometheus-WHATEVER-VERSION-YOU-HAVE' directory, to '/usr/local/bin/' | ||
<nowiki>sudo cp prometheus /usr/local/bin/ | <nowiki>sudo cp prometheus /usr/local/bin/ | ||
| Line 40: | Line 37: | ||
<nowiki>sudo cp prometheus.yml /etc/prometheus/prometheus.yml</nowiki> | <nowiki>sudo cp prometheus.yml /etc/prometheus/prometheus.yml</nowiki> | ||
| − | + | ==Changing Ownership Of The Files== | |
Change ownership of the files to the prometheus user we created: | Change ownership of the files to the prometheus user we created: | ||
<nowiki>sudo chown prometheus:prometheus /usr/local/bin/prometheus | <nowiki>sudo chown prometheus:prometheus /usr/local/bin/prometheus | ||
| Line 48: | Line 45: | ||
sudo chown -R prometheus:prometheus /var/lib/prometheus</nowiki> | sudo chown -R prometheus:prometheus /var/lib/prometheus</nowiki> | ||
| − | + | =Create Systemd Service for Prometheus= | |
| − | + | ==Creating Systemd Service File== | |
Create the service file itself: | Create the service file itself: | ||
<nowiki>sudo vim /etc/systemd/system/prometheus.service</nowiki> | <nowiki>sudo vim /etc/systemd/system/prometheus.service</nowiki> | ||
| Line 78: | Line 75: | ||
</nowiki> | </nowiki> | ||
| − | + | ==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: | Once the service file is created and all the files/directories are where they should be, the Prometheus service can be started: | ||
<nowiki> | <nowiki> | ||
| Line 99: | Line 96: | ||
<nowiki>Prometheus Server is Healthy</nowiki> | <nowiki>Prometheus Server is Healthy</nowiki> | ||
| − | + | =Configure Prometheus= | |
| − | + | ==File Location== | |
Configuring Prometheus requires the editing of the '/etc/prometheus/prometheus.yml' file. | Configuring Prometheus requires the editing of the '/etc/prometheus/prometheus.yml' file. | ||
| − | + | ==Example File== | |
Below is a basic config file for Prometheus: | Below is a basic config file for Prometheus: | ||
<nowiki> | <nowiki> | ||
Revision as of 03:00, 28 March 2026
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']
# If you additionally use the node exporter, include the below with it's job name and port number
- job_name: 'node'
static_configs:
- targets: ['localhost:NODE_PORT']
When the config file is updated, update Prometheus via:
curl -X POST http://localhost:PORT/-/reload