Новые каталоги
This commit is contained in:
141
PostgreSQL/PostgreSQL_Exporter.md
Normal file
141
PostgreSQL/PostgreSQL_Exporter.md
Normal file
@ -0,0 +1,141 @@
|
||||
Устанавливаю согласно инструкции из:
|
||||
|
||||
https://github.com/prometheus-community/postgres_exporter
|
||||
|
||||
Подключаюсь к нужной машине
|
||||
```sh
|
||||
ssh igor@ccalm.org -p 2200
|
||||
```
|
||||
|
||||
Configure postgresql.conf
|
||||
```conf
|
||||
shared_preload_libraries = 'pg_stat_statements'
|
||||
pg_stat_statements.track = all
|
||||
```
|
||||
|
||||
## 1. Установка Docker и Docker Compose
|
||||
Если Docker не установлен, установим его:
|
||||
```sh
|
||||
sudo apt update && sudo apt upgrade -y &&
|
||||
sudo apt install -y docker.io docker-compose &&
|
||||
sudo systemctl enable --now docker
|
||||
```
|
||||
|
||||
## 2. Установка postgres-exporter в докере из заранее подготовленного образа
|
||||
|
||||
```sh
|
||||
sudo mkdir -p /opt/postgres-exporter &&
|
||||
sudo chown $USER:$USER /opt/postgres-exporter &&
|
||||
cd /opt/postgres-exporter
|
||||
```
|
||||
|
||||
Создаю файл с настройками
|
||||
```sh
|
||||
cd /opt/postgres-exporter/ &&
|
||||
cat > docker-compose.yml <<'EOF'
|
||||
services:
|
||||
postgres-exporter:
|
||||
image: quay.io/prometheuscommunity/postgres-exporter
|
||||
container_name: postgres-exporter
|
||||
restart: unless-stopped
|
||||
network_mode: "host"
|
||||
environment:
|
||||
DATA_SOURCE_URI: "postgresql://postgres:309A86FF65A78FB428F4E38DFE35F730@localhost:5432/postgres?sslmode=disable"
|
||||
volumes:
|
||||
- ./postgres_exporter.yml:/etc/postgres_exporter.yml
|
||||
command:
|
||||
- "--config.file=/etc/postgres_exporter.yml"
|
||||
|
||||
EOF
|
||||
```
|
||||
|
||||
Создаём файл с настройками
|
||||
```sh
|
||||
cd /opt/postgres-exporter/ &&
|
||||
cat > postgres_exporter.yml <<'EOF'
|
||||
collectors:
|
||||
- database
|
||||
- index
|
||||
- query
|
||||
- table
|
||||
EOF
|
||||
```
|
||||
Запускаю:
|
||||
```sh
|
||||
cd /opt/postgres-exporter &&
|
||||
sudo docker-compose up -d
|
||||
```
|
||||
|
||||
Проверяю запущен ли докер
|
||||
```sh
|
||||
sudo docker ps
|
||||
```
|
||||
|
||||
Testing with:
|
||||
```sh
|
||||
curl "http://127.0.0.1:9187/metrics"
|
||||
```
|
||||
|
||||
Посмотреть журнал за сегодня:
|
||||
```sh
|
||||
journalctl --since today
|
||||
```
|
||||
|
||||
Настраиваем простую авторизацию при помощи HAProxy для скачивания при помощи удаленного сервера
|
||||
|
||||
```sh
|
||||
sudo mcedit /etc/haproxy/haproxy.cfg
|
||||
```
|
||||
Настраиваем:
|
||||
```text
|
||||
acl v_metrics_nd path_beg /metrics_nd
|
||||
acl v_basic_auth http_auth(prometheus_list)
|
||||
http-request auth realm Metrics_org_ccalm_nd if v_metrics_nd !v_basic_auth
|
||||
use_backend b_metrics_nd if v_metrics_nd v_basic_auth
|
||||
|
||||
backend b_metrics_nd
|
||||
mode http
|
||||
option http-keep-alive
|
||||
http-request replace-path .* /metrics
|
||||
server web1 127.0.0.1:9100 check
|
||||
```
|
||||
|
||||
Проверяем
|
||||
```sh
|
||||
haproxy -f /etc/haproxy/haproxy.cfg -c
|
||||
````
|
||||
Перезагружаем:
|
||||
```sh
|
||||
sudo systemctl restart haproxy
|
||||
````
|
||||
|
||||
|
||||
|
||||
Подключаюсь к машине где Prometeus:
|
||||
|
||||
```sh
|
||||
ssh igor@192.168.200.84 -p 22
|
||||
```
|
||||
|
||||
Перезагружаем prometheus чтобы он начал собирать метрики
|
||||
```sh
|
||||
sudo systemctl restart prometheus
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
Теперь можно настраивать графану, вот готовыдашбоард
|
||||
Открыть Grafana
|
||||
Перейти в Dashboards → Import
|
||||
Вставить ID: 9628
|
||||
Выбрать источник данных Prometheus (с PostgreSQL Exporter)
|
||||
Нажать Import
|
||||
|
||||
|
||||
Теперь можно настраивать графану, вот готовыдашбоард
|
||||
Открыть Grafana
|
||||
Перейти в Dashboards → Import
|
||||
Вставить ID: 12273
|
||||
Выбрать источник данных Prometheus (с PostgreSQL Exporter)
|
||||
Нажать Import
|
||||
Reference in New Issue
Block a user