PostgreSQL Exporter для докера - Прометей - PullRequest
0 голосов
/ 02 ноября 2019

Я читаю эту страницу годами, и теперь мне нужна помощь. Я начинаю настраивать Prometheus для сбора метрик из контейнеров Docker Swarm и Docker. Он действительно хорошо работает с cAdvisor и Node Exporter, но теперь у меня возникают проблемы со сбором метрик из Docker-контейнера PostgreSQL. Я использую этот экспортер -> https://github.com/wrouesnel/postgres_exporter Это сервис в docker-compose.yml:

postgresql-exporter:
  image: wrouesnel/postgres_exporter
  ports:
    - 9187:9187
  networks:
    - backend
  environment:
    - DATA_SOURCE_NAME=postgresql://example:<password>@localhost:5432/example?sslmode=disable

И это в prometheus.yml

  - job_name: 'postgresql-exporter'
    static_configs:
      - targets: ['postgresql-exporter:9187']

У нас есть два стека, один с базой данных, а другой со стеком мониторинга.

Регистрируется в сервисе postgresql:

monitoring_postgresql-exporter.1.krslcea4hz20@master1.xxx.com    | time="2019-11-02T16:12:20Z" level=error msg="Error opening connection to database (postgresql://example:PASSWORD_REMOVED@localhost:5432/example?sslmode=disable): dial tcp 127.0.0.1:5432: connect: connection refused" source="postgres_exporter.go:1403"

monitoring_postgresql-exporter.1.krslcea4hz20@master1.xxx.com    | time="2019-11-02T16:12:29Z" level=info msg="Established new database connection to \"localhost:5432\"." source="postgres_exporter.go:814"

monitoring_postgresql-exporter.1.krslcea4hz20@master1.xxx.com    | time="2019-11-02T16:12:30Z" level=info msg="Established new database connection to \"localhost:5432\"." source="postgres_exporter.go:814"

monitoring_postgresql-exporter.1.krslcea4hz20@master1.xxx.com    | time="2019-11-02T16:12:32Z" level=info msg="Established new database connection to \"localhost:5432\"." source="postgres_exporter.go:814"

monitoring_postgresql-exporter.1.krslcea4hz20@master1.xxx.com    | time="2019-11-02T16:12:35Z" level=error msg=**"Error opening connection to database (postgresql://example:PASSWORD_REMOVED@localhost:5432/example?sslmode=disable): dial tcp 127.0.0.1:5432: connect: connection refused" source="postgres_exporter.go:1403"**

Но когда я смотрю в разделе целей prometheus, postresqlконечная точка -exporter говорит "UP" И когда я проверяю метрику pg_up, она говорит 0, нет соединения. Любая идея, как я могу решить это? Любая помощь будет оценена, спасибо!

РЕДАКТИРОВАТЬ: Вот конфиг службы dog службы PostgreSQL DB:

  pg:
    image: registry.xxx.com:443/pg:201908221000
    environment:
      - POSTGRES_DB=example
      - POSTGRES_USER=example
      - POSTGRES_PASSWORD=example
    volumes:
      - ./postgres/db_data:/var/lib/postgresql/data
    networks:
      - allnet
    deploy:
      mode: replicated
      replicas: 1
      placement:
        constraints: [node.role == manager]
      restart_policy:
        condition: on-failure
        max_attempts: 3
        window: 120s

Спасибо

...