Prometheus Postgres and Nginx Exporter
Prometheus Postgres and Nginx Exporter
Postgres Exporter
docker-compose.yaml:
services:
postgres:
container_name: postgres
image: postgres:18.0
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: pass
POSTGRES_DB: postgres
ports:
- 5432:5432
postgres-exporter:
container_name: postgres-exporter
image: prometheuscommunity/postgres-exporter
depends_on:
- postgres
ports:
- 9187:9187
environment:
DATA_SOURCE_NAME: "postgresql://postgres:pass@postgres:5432/postgres?sslmode=disable"
# docker compose up -d
# curl -XGET http://localhost:9187/metrics
# docker exec -it postgres psql -U postgres -d postgres
CREATE TABLE test(id SERIAL PRIMARY KEY, value TEXT);
INSERT INTO test(value)VALUES ('hello1');
INSERT INTO test(value)VALUES ('hello2');
# curl -s http://localhost:9187/metrics | grep pg_stat_database_xact_commit
Nginx Exporter
default.conf:
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
# включим prometheus модуль stub_status
location /stub_status {
stub_status;
}
}
docker-compose.yaml:
services:
nginx:
container_name: nginx
image: nginx
ports:
- 8080:80
volumes:
- './default.conf:/etc/nginx/conf.d/default.conf'
nginx-exporter:
image: nginx/nginx-prometheus-exporter
container_name: nginx-exporter
depends_on:
- nginx
ports:
- 9113:9113
command:
- '--nginx.scrape-uri=http://nginx:80/stub_status'
# docker compose up -d
# for i in {1..20}; do curl http://localhost:8080; done
# curl -XGET http://localhost:9113/metrics
Prometheus
prometheus.yaml:
global:
scrape_interval: 15s
scrape_timeout: 10s
scrape_configs:
- job_name: 'nginx-exporter'
static_configs:
- targets:
- 'nginx-exporter:9113'
- job_name: 'postgres-exporter'
static_configs:
- targets:
- 'postgres-exporter:9187'
docker-compose.yaml:
services:
nginx:
container_name: nginx
image: nginx
ports:
- 8080:80
volumes:
- './default.conf:/etc/nginx/conf.d/default.conf'
nginx-exporter:
image: nginx/nginx-prometheus-exporter
container_name: nginx-exporter
depends_on:
- nginx
ports:
- 9113:9113
command:
- '--nginx.scrape-uri=http://nginx:80/stub_status'
postgres:
container_name: postgres
image: postgres
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: pass
POSTGRES_DB: postgres
ports:
- 5432:5432
postgres-exporter:
container_name: postgres-exporter
image: prometheuscommunity/postgres-exporter
depends_on:
- postgres
ports:
- 9187:9187
environment:
DATA_SOURCE_NAME: "postgresql://postgres:pass@postgres:5432/postgres?sslmode=disable"
prometheus:
image: prom/prometheus
volumes:
- './prometheus.yaml:/etc/prometheus/prometheus.yaml'
ports:
- 9090:9090
command:
- '--config.file=/etc/prometheus/prometheus.yaml'
# docker compose up -d
Комментарии пользователей
Анонимам нельзя оставоять комментарии, зарегистрируйтесь!
|