Prometheus is a powerful and widely used open-source monitoring and alerting system. Its ability to store time-series data and query it in real-time has made it a popular choice for monitoring various aspects of IT infrastructure. In this guide, we will walk you through the process of how to install and configure Prometheus on Arch Linux.
How to Install and Configure Prometheus on Arch Linux
Prerequisites
Before you start, ensure that your Arch Linux system is up-to-date. You can achieve this by running the following command:
sudo pacman -Syu
Install Prometheus on Arch Linux
To install Prometheus on Arch Linux, we will use the yay package manager. If you don’t have yay installed, follow our guide on how to install yay on Arch Linux.
Once you have yay installed, run the following command:
yay -S prometheus
This command will download and install Prometheus from the Arch User Repository (AUR).
Configure Prometheus on Arch Linux
Now that Prometheus is installed, we need to configure it. First, create a new directory to store the Prometheus configuration file:
sudo mkdir /etc/prometheus
Next, create a new Prometheus configuration file using your favorite text editor. In this guide, we will use nano. If you don’t have nano installed, you can follow our guide on how to install nano on Arch Linux.
sudo nano /etc/prometheus/prometheus.yml
Paste the following content into the configuration file:
global:
scrape_interval: 15s
external_labels:
monitor: 'example-monitor'
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
Save and exit the file. This configuration sets up Prometheus to scrape its own metrics every 15 seconds.
Create a Systemd Service
To manage the Prometheus service using systemd, we need to create a service file. Create a new file called prometheus.service
in the /etc/systemd/system
directory:
sudo nano /etc/systemd/system/prometheus.service
Paste the following content into the service file:
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
ExecStart=/usr/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
Save and exit the file.
Start and Enable Prometheus Service
Now that we have created the systemd service file, we can start and enable the Prometheus service. Run the following commands to start the service and enable it to start at boot:
sudo systemctl start prometheus.service
sudo systemctl enable prometheus.service
Verify Prometheus Installation on Arch Linux
To verify that Prometheus is running and accessible, open your web browser and visit http://your_server_ip:9090
. You should see the Prometheus web interface.
Additionally, you can check the status of the Prometheus service using the following command:
sudo systemctl status prometheus.service
If everything is working correctly, you should see output similar to the following:
● prometheus.service - Prometheus
Loaded: loaded (/etc/systemd/system/prometheus.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2023-04-18 10:00:00 UTC; 2min 30s ago
Main PID: 12345 (prometheus)
Tasks: 12 (limit: 4915)
Memory: 35.8M
CGroup: /system.slice/prometheus.service
└─12345 /usr/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
This output confirms that the Prometheus service is active and running.
Configure Firewalls (Optional)
If you have a firewall enabled on your Arch Linux system, you might need to configure it to allow incoming connections to Prometheus. For instance, if you are using firewalld
, you can follow our guide on how to configure firewall on Arch Linux to allow incoming connections on port 9090.
Conclusion
Congratulations! You have successfully installed and configured Prometheus on your Arch Linux system. You can now begin to monitor your IT infrastructure using Prometheus. To further enhance your monitoring capabilities, you can explore additional tools such as Grafana for creating visualizations or learn how to install and configure other monitoring systems like Zabbix on Arch Linux.