Help us learn about your current experience with the documentation. Take the survey.

PostgreSQL 服务器导出器

  • 版本:免费版、高级版、旗舰版
  • 产品:GitLab 自管版

PostgreSQL 服务器导出器 允许您导出各种 PostgreSQL 指标。

对于自行编译安装的实例,您必须自行安装和配置它。

要启用 PostgreSQL 服务器导出器:

  1. 启用 Prometheus

  2. 编辑 /etc/gitlab/gitlab.rb 文件并启用 postgres_exporter

    postgres_exporter['enable'] = true

    如果 PostgreSQL 服务器导出器配置在单独的节点上,请确保本地地址已trust_auth_cidr_addresses 中列出,否则导出器将无法连接到数据库。

  3. 保存文件并重新配置 GitLab以使更改生效。

Prometheus 开始从暴露在 localhost:9187 下的 PostgreSQL 服务器导出器收集性能数据。

高级配置

在大多数情况下,PostgreSQL 服务器导出器使用默认配置即可正常工作,您无需更改任何设置。要进一步自定义 PostgreSQL 服务器导出器,请使用以下配置选项:

  1. 编辑 /etc/gitlab/gitlab.rb 文件:

    # 要连接的数据库名称。
    postgres_exporter['dbname'] = 'pgbouncer'
    # 登录时使用的用户名。
    postgres_exporter['user'] = 'gitlab-psql'
    # 用户的密码。
    postgres_exporter['password'] = ''
    # 要连接的主机。以 '/' 开头的值用于 Unix 域套接字(默认为 'localhost')。
    postgres_exporter['host'] = 'localhost'
    # 要绑定的端口(默认为 '5432')。
    postgres_exporter['port'] = 5432
    # 是否使用 SSL。有效选项包括:
    #   'disable'(不使用 SSL),
    #   'require'(始终使用 SSL 并跳过验证,这是默认值),
    #   'verify-ca'(始终使用 SSL 并验证服务器提供的证书是否由可信 CA 签名),
    #   'verify-full'(始终使用 SSL 并验证服务器提供的证书是否由可信 CA 签名,以及服务器主机名是否与证书中的主机名匹配)。
    postgres_exporter['sslmode'] = 'require'
    # 如果未提供 application_name,则使用的备用名称。
    postgres_exporter['fallback_application_name'] = ''
    # 连接的最大等待时间(秒)。零或未指定表示无限期等待。
    postgres_exporter['connect_timeout'] = ''
    # 证书文件位置。文件必须包含 PEM 编码的数据。
    postgres_exporter['sslcert'] = 'ssl.crt'
    # 密钥文件位置。文件必须包含 PEM 编码的数据。
    postgres_exporter['sslkey'] = 'ssl.key'
    # 根证书文件的位置。文件必须包含 PEM 编码的数据。
    postgres_exporter['sslrootcert'] = 'ssl-root.crt'
  2. 保存文件并重新配置 GitLab 以使更改生效。