Что такое Apache Exporter? Apache Exporter — это экспортер Prometheus для собора Apache-метрик, которые берутся из отчетов о состоянии Apache-сервера генерируемых модулем mod_status
и доступным по URL http://127.0.0.1/server-status/?auto
.
В этой статье я покажу, как создать страницу с отчетами о состояния Apache-сервера, как скомпилировать Apache Exporter с помощью go get
и как его настроить с помощью systemd сервис-менеджера в Ubuntu и CentOS.
Дельный Совет: Установка Node Exporter в Ubuntu и CentOS! Читать Далее →
Активация Server-Status в Apache
Чтобы активировать отчеты о статусе сервера, создайте конфигурационный файл:
# Ubuntu $ sudo vi /etc/apache2/conf-available/server-status.conf # CentOS $ sudo vi /etc/httpd/conf.d/server-status.conf
Со следующим содержимым:
ExtendedStatus on <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from 127.0.0.1 </Location>
Перезапустите Apache:
# Ubuntu $ cd /etc/apache2/conf-enabled $ sudo ln -s ../conf-available/server-status.conf server-status.conf && cd $ sudo systemctl restart apache2 # CentOS $ sudo systemctl restart httpd
Проверьте страницу server-status
:
$ curl http://127.0.0.1/server-status
Установка Go и Git
Go нам нужен для компиляции apache_exporter
из исходников.
Дельный Совет: GoLang — Установка Go в MacOS, Ubuntu, CentOS! Читать далее →
Скачайте и установите последнюю версию Go для своей платформы с официальной страницы загрузки (текущая версия go1.11).
$ curl -O https://dl.google.com/go/go1.11.linux-amd64.tar.gz $ sudo tar -C /usr/local -xvzf go1.11.linux-amd64.tar.gz $ echo "export GOPATH=$HOME/go" >> ~/.profile $ echo "export PATH=$PATH:/usr/local/go/bin" >> ~/.profile $ source ~/.profile $ go version go version go1.11 linux/amd64
Нам также необходим пакет git
, чтобы скачать apache_exporter
с GitHub с помощью команды go get
, в противном случае вы можете получить следующую ошибку:
go: missing Git command. See https://golang.org/s/gogetcmd
package github.com/neezgee/apache_exporter: exec: «git»: executable file not found in $PATH
Установите Git:
# Ubuntu $ sudo apt install git # CentOS $ sudo yum install git
Apache Exporter: Установка и Настройка
Создайте непривилегированного пользователя apache_exporter
:
$ sudo useradd apache_exporter -s /sbin/nologin
Скачайте и скомпилируйте Apache Exporter:
$ go get -v github.com/Lusitaniae/apache_exporter $ sudo cp ~/go/bin/apache_exporter /usr/sbin/
Создайте файл systemd-сервиса /etc/systemd/system/apache_exporter.service
:
[Unit] Description=Apache Exporter [Service] User=apache_exporter EnvironmentFile=/etc/sysconfig/apache_exporter ExecStart=/usr/sbin/apache_exporter $OPTIONS [Install] WantedBy=multi-user.target
Создайте sysconfig файл:
$ sudo mkdir -p /etc/sysconfig $ sudo touch /etc/sysconfig/apache_exporter
Используйте этот файл, чтобы прописать опции передаваемые сервису, например:
OPTIONS="-scrape_uri='http://127.0.0.1/server-status/?auto'"
Чтобы узнать все доступные опции, выполните:
$ /usr/sbin/apache_exporter --help
Перезапустите systemd и настройте apache_exporter
на автостарт при загрузке системы:
$ sudo systemctl daemon-reload $ sudo systemctl enable apache_exporter
Запустите сервис apache_exporter
:
$ sudo systemctl start apache_exporter
После установки Apache Exporter, проверьте что метрики экспортируются:
$ curl http://localhost:9117/metrics
Добавить Источник Apache Exporter в Prometheus
Дельный Совет: Установка системы мониторинга Prometheus с помощью Docker в Ubuntu и CentOS! Читать Далее →
Теперь все, что осталось сделать — объявить серверу Prometheus о новом источнике.Это необходимо сделать в конфигурации Prometheus, поскольку Apache Exporter просто отдает метрики, а Prometheus собирает их из источников, о которых он знает.
Откройте конфигурационный файл Prometheus prometheus.yml
и добавьте свою машину в раздел scrape_configs
:
scrape_configs: - job_name: 'apache' static_configs: - targets: ['$NODE_IP:9117']
Перезагрузите конфигурацию Prometheus и вы сможете получить доступ к Apache-метрикам своего сервера из Prometheus!
The configuration is wrong
USE:
without String
Thanks.
Actually you don’t need to use this configuration if inside apache configuration you define: Allow from localhost # instead of 127.0.0.1 🙂
OPTIONS=»—scrape_uri=’http://127.0.0.1/server-status/?auto'»