6.8 KiB
Alias | Tag | Date | DocType | Hierarchy | TimeStamp | location | CollapseMetaTable | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
2022-03-19 | Personal | NonRoot |
|
Yes |
Parent:: Selfhosting, Configuring Caddy, Server Tools
name Save
type command
action Save current file
id Save
^button-ConfiguringPrometheusNSave
Configuring Prometheus
title: Summary
collapse: open
This not runs through the installation and use of Prometheus as a monitoring tool.
Prometheus interacts better with json logs rather than common log language, which is caddy's output.
style: number
Introduction
Prometheus is a free and open-source monitoring and alerting tool that was initially used for monitoring metrics at SoundCloud back in 2012. It is written in Go programming language.
Prometheus monitors and records real-time events in a time-series database. Since then it has grown in leaps and bounds and had been adopted by many organizations to monitor their infrastructure metrics. Prometheus provides flexible queries and real-time alerting which helps in quick diagnosis and troubleshooting of errors.
Prometheus comprises the following major components:
- The main Prometheus server for scraping and storing time-series data.
- Unique exporters for services such as Graphite, HAProxy, StatsD and so much more
- An alert manager for handling alerts
- A push-gateway for supporting transient jobs
- Client libraries for instrumenting application code
Installing Prometheus
Installing the main modules
But first, we need to create the configuration and data directories for Prometheus.
To create the configuration directory, run the command:
~~~bash
sudo mkdir -p /etc/prometheus
~~~
For the data directory, execute:
~~~bash
sudo mkdir -p /var/lib/prometheus
~~~
Once the directories are created, grab the compressed installation file:
~~~bash
wget https://github.com/prometheus/prometheus/releases/download/v2.31.0/prometheus-2.31.0.linux-amd64.tar.gz
~~~
Once downloaded, extract the tarball file.
~~~bash
tar -xvf prometheus-2.31.3.linux-amd64.tar.gz
~~~
Then navigate to the Prometheus folder.
~~~bash
cd prometheus-2.31.3.linux-amd64
~~~
Once in the directory move the prometheus
and promtool
binary files to /usr/local/bin/
folder.
~~~bash
sudo mv prometheus promtool /usr/local/bin/
~~~
Additionally, move console files in console
directory and library files in the console_libraries
directory to /etc/prometheus/
directory.
~~~bash
sudo mv consoles/ console_libraries/ /etc/prometheus/
~~~
Also, ensure to move the prometheus.yml template configuration file to the /etc/prometheus/
directory.
~~~bash
sudo mv prometheus.yml /etc/prometheus/prometheus.yml
~~~
At this point, Prometheus has been successfully installed. To check the version of Prometheus installed, run the command:
~~~bash
prometheus --version
~~~
Output:
~~~bash
prometheus, version 2.31.3 (branch: HEAD, revision: f29caccc42557f6a8ec30ea9b3c8c089391bd5df)
build user: root@5cff4265f0e3
build date: 20211005-16:10:52
go version: go1.17.1
platform: linux/amd64
~~~
~~~bash
promtool --version
~~~
Output:
~~~bash
promtool, version 2.31.3 (branch: HEAD, revision: f29caccc42557f6a8ec30ea9b3c8c089391bd5df)
build user: root@5cff4265f0e3
build date: 20211005-16:10:52
go version: go1.17.1
platform: linux/amd64
~~~
If your output resembles what I have, then you are on the right track. In the next step, we will create a system group and user.
Permissions & User Management
It's essential that we create a Prometheus group and user before proceeding to the next step which involves creating a system file for Prometheus.
To create a prometheus
group execute the command:
~~~bash
sudo groupadd --system prometheus
~~~
Thereafter, Create prometheus
user and assign it to the just-created prometheus
group.
~~~bash
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
~~~
Next, configure the directory ownership and permissions as follows.
~~~bash
sudo chown -R prometheus:prometheus /etc/prometheus/ /var/lib/prometheus/$ sudo chmod -R 775 /etc/prometheus/ /var/lib/prometheus/
~~~
The only part remaining is to make Prometheus a systemd service so that we can easily manage its running status.
Configuring the service
Using your favorite text editor, create a systemd service file:
~~~bash
sudo nano /etc/systemd/system/prometheus.service
~~~
Paste the following lines of code.
~~~bash
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Restart=always
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 \
--web.listen-address=0.0.0.0:9090
[Install]
WantedBy=multi-user.target
~~~
Save the changes and exit the systemd file.
Then proceed and start the Prometheus service.
~~~bash
sudo systemctl start prometheus
~~~
Enable the Prometheus service to run at startup. Therefore invoke the command:
~~~bash
sudo systemctl enable prometheus
~~~
Then confirm the status of the Prometheus service.
~~~bash
sudo systemctl status prometheus
~~~
Configuration of user acccess
Finally, to access Prometheus, parameter your reverse-proxy (Configuring Caddy) to point back to the service.
It is accessible below, under internal port 9090:
https://prometheus.mfxm.fr