Создание юзера и директорий
groupadd --system prometheus
useradd -s /sbin/nologin --system -g prometheus prometheus
mkdir /var/lib/prometheus
for i in rules rules.d files_sd; do mkdir -p /etc/prometheus/${i} ; done
apt update
apt -y install wget curl vim
mkdir -p /tmp/prometheus && cd /tmp/prometheus && curl -L $( curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d ' "' -f 4 | head -n 1) | tar xzf -
cd prometheus* /
mv prometheus promtool /usr/local/bin/
mv prometheus.yml /etc/prometheus/prometheus.yml
mv consoles/ console_libraries/ /etc/prometheus/
cd /tmp && rm -r ./prometheus
Создание сервиса для автозапуска
Скопировать файл monitoring/prometheus/prometheus.service
в папку /etc/systemd/system/prometheus.service
for i in rules rules.d files_sd; do chown -R prometheus:prometheus /etc/prometheus/${i} ; done
for i in rules rules.d files_sd; do chmod -R 775 /etc/prometheus/${i} ; done
chown -R prometheus:prometheus /var/lib/prometheus/
Добавление postgres_exporter
Открыть файл с конфигом прометеуса и добавить в scrape_configs новую цель для скрапа
nano /etc/prometheus/prometheus.yml
- job_name : ' postgres_exporter'
static_configs :
- targets : ['127.0.0.1:9187']
- job_name : ' pgbouncer_exporter'
static_configs :
- targets : ['127.0.0.1:9127']
- job_name : ' redis_exporter'
static_configs :
- targets : ['127.0.0.1:9121']
- job_name : ' node_exporter'
static_configs :
- targets : ['127.0.0.1:9167']
- job_name : ' mongodb_exporter'
static_configs :
- targets : ['127.0.0.1:9216']
systemctl daemon-reload
systemctl enable prometheus
systemctl start prometheus