【问题标题】:How to deploy postgres_exporter on the Docker and connect to prometheus如何在 Docker 上部署 postgres_exporter 并连接到 prometheus
【发布时间】:2018-12-19 07:56:55
【问题描述】:

我在 Debian 8 上安装了 docker 的服务器。容器中需要该方法。该容器安装了 postgres 9.6。我想通过PostgreSQL的postgres_exporter在prometheus中设置pg_stat_statements表的数据收集,然后通过grafana看图。部署grafana和Prometheus按照说明做了:

$ git clone https://github.com/stefanprodan/dockprom
$ cd dockprom
$ docker-compose up -d

在 prometheus.yml 中添加:

- job_name: 'postgres-exporter'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9187']

但我对 postgres-exporter 有疑问: Prometheus targets status

获取了 PostgreSQL 的导出统计信息:link。我尝试使用不同的端口部署到 docker,但 Prometheus 不想连接到他。请告诉我,如何正确安装和部署?

【问题讨论】:

  • 如果你不在 docker-compose.yml 中使用network_mode: host,你在容器中的 localhost 与你主机中的 localhost 不同。您可以定义自己的 docker 网络或在每个 docker-compose 服务中声明 network_mode: host 以实现它们之间的连接。
  • 谢谢,成功了!

标签: postgresql docker prometheus


【解决方案1】:

如果你只想抓取 postgresdb 指标,你可以使用 docker 命令而不是 docker-compose

sudo docker run --name postgres-exporter -e DATA_SOURCE_NAME="postgresql://<postgresdb_user_name>:<postgres_db_password>@<postgres_vm_ip>:<postgresdb_port>/?sslmode=disable" -p 9187:9187 wrouesnel/postgres_exporter

对我来说,我执行的完整命令是

sudo docker run --name postgres-exporter -e DATA_SOURCE_NAME="postgresql://postgres:postgrespassword@10.0.0.31:5432/?sslmode=disable" -p 9187:9187 wrouesnel/postgres_exporter

然后在 prometheus.yml 文件中添加抓取点

- job_name: postgres_100031
  static_configs:
  - targets: ['10.0.0.31:9187']

重启 Prometheus 服务

【讨论】:

    猜你喜欢
    • 2020-08-19
    • 1970-01-01
    • 2022-07-12
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    • 2022-10-25
    • 2020-05-08
    • 1970-01-01
    相关资源
    最近更新 更多