Prometheus + Node Exporter — Установка

Создадим группу и пользователя:

groupadd --system prometheus
useradd -s /sbin/nologin --system -g prometheus prometheus

Переходим на официальный сайт и копируем ссылку на скачивание:

https://prometheus.io/download/

Скачиваем архив:

wget https://github.com/prometheus/prometheus/releases/download/v2.5.0/prometheus-2.5.0.linux-amd64.tar.gz

Разархивируем:

tar -xf prometheus-2.5.0.linux-amd64.tar.gz

Для удобства переименуем папку:

mv prometheus-2.5.0.linux-amd64 prometheus

Переместим бинарный файл Prometheus в «/usr/local/bin/«:

cp -a prometheus/prometheus /usr/local/bin/

Создадим директории для Prometheus:

mkdir /etc/prometheus
mkdir /var/lib/prometheus

Копируем необходимые папки и файлы для работы Prometheus:

cp -R prometheus/consoles /etc/prometheus/
cp -R prometheus/console_libraries /etc/prometheus/
cp prometheus/prometheus.yml /etc/prometheus/

Меняем владельца папки:

chown -R prometheus:prometheus /var/lib/prometheus/

 

Создадим сервис для Prometheus:

cat >/etc/systemd/system/prometheus.service  << EOF
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
Environment="GOMAXPROCS=2"
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
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 \
  --web.external-url=

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target
EOF

«GOMAXPROCS=2» — количество ядер в вашей системе

Перечитываем демонов:

systemctl daemon-reload

Добавляем в автозагрузку и запускаем:

systemctl enable prometheus
systemctl start prometheus

Проверим работу службы:

systemctl status prometheus

 

Сбор метрик.

Для этого необходимо установить «node-exporter»

Переходим на официальный сайт и копируем ссылку на скачивание:

https://prometheus.io/download/

Скачиваем архив:

wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz

Разархивируем:

tar -xf node_exporter-0.17.0.linux-amd64.tar.gz

Копируем бинарный файл в «/usr/local/bin/«:

cp -a node_exporter-0.17.0.linux-amd64/node_exporter /usr/local/bin/

Создадим сервис для «Node Exporter«:

cat > /etc/systemd/system/node_exporter.service << EOF
[Unit]
Description=Node Exporter

[Service]
ExecStart=/usr/local/bin/node_exporter

[Install]
WantedBy=default.target
EOF

Перечитываем демонов:

systemctl daemon-reload

Добавляем в автозагрузку и запускаем:

systemctl enable node_exporter
systemctl start node_exporter

Проверим работу службы:

systemctl status node_exporter

Пример конфигурации для сбора метрик с сервера, где установлен Prometheus:

/etc/prometheus/prometheus.yml
global:
  scrape_interval: "10s"
  evaluation_interval: "10s"

scrape_configs:
- job_name: "prometheus"
  static_configs:
  - targets: ['localhost:9090']
- job_name: "node"
  static_configs:
  - targets:
    - "localhost:9100"

Для добавления серверов для сбора с них метрик, нужно на них установить «node-exporter«:

И перечислить их в в файле конфигурации Prometheus:

scrape_configs:
  - job_name: 'prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['web:9100']
        labels:
          host: WEB
      - targets: ['db:9100']
        labels:
          host: DB

Метки: Метки

Подписаться
Уведомить о
guest

0 комментариев
Межтекстовые Отзывы
Посмотреть все комментарии