Prometheus 是一个开源监控系统,具有维度数据模型、灵活的查询语言和现代化的警报方法。

此页面向您展示如何使用 PostgreSQL Exporter 将您的服务遥测数据导出到 Prometheus。

集成之前

为了减少延迟和潜在的数据传输成本,请将 Prometheus 和 PostgreSQL Exporter 安装在与您的 Timescale Cloud 服务相同的 AWS 区域中的机器上。

要导出您的数据,请执行以下操作

  1. 创建一个用户以访问有关您的 Timescale Cloud 服务的遥测数据

    1. 连接到您的 Timescale Cloud 服务

      对于 Timescale Cloud,在 Timescale 控制台中打开一个 SQL 编辑器。对于自托管,请使用 psql

    2. 创建一个名为 monitoring 的用户并设置安全密码

      CREATE USER monitoring WITH PASSWORD '<password>';
    3. 授予 pg_read_all_stats 权限给 monitoring 用户

      GRANT pg_read_all_stats to monitoring;
  2. 将关于您的 Timescale Cloud 服务的遥测数据导入到 PostgreSQL Exporter

    1. 将 PostgreSQL Exporter 连接到您的 Timescale Cloud 服务

      使用您的连接详细信息导入关于您的 Timescale Cloud 服务的遥测数据。您以 monitoring 用户身份连接

      • 本地安装
        export DATA_SOURCE_NAME="postgres://monitoring:<password>@<host>.tsdb.cloud.timescale.com:<port>/tsdb?sslmode=require"
        ./postgres_exporter
      • Docker
        docker run -d \
        -e DATA_SOURCE_NAME="postgres://monitoring:<password>@<host>.tsdb.cloud.timescale.com:<port>/tsdb?sslmode=require" \
        -p 9187:9187 \
        prometheuscommunity/postgres-exporter
    2. 以 Prometheus 格式检查您的 Timescale Cloud 服务的指标

      • 浏览器

        导航到 http://<exporter-host>:9187/metrics

      • 命令行

        curl http://<exporter-host>:9187/metrics
  3. 配置 Prometheus 以抓取指标

    1. 在您的 Prometheus 安装中,更新 prometheus.yml 以将您的 PostgreSQL Exporter 实例指向为抓取目标。在以下示例中,您将 <exporter-host> 替换为 PostgreSQL Exporter 的主机名或 IP 地址。

      global:
      scrape_interval: 15s
      scrape_configs:
      - job_name: 'postgresql'
      static_configs:
      - targets: ['<exporter-host>:9187']

      如果 prometheus.yml 在安装期间未创建,请手动创建它。如果您正在使用 Docker,您可以在运行 PostgreSQL Exporter 的容器的 Inspect > Networks 中找到 IPAddress。

    2. 重启 Prometheus。

    3. http://<prometheus-host>:9090/targetshttp://<prometheus-host>:9090/tsdb-status 检查 Prometheus UI。

      您将看到 PostgreSQL Exporter 目标以及从中抓取的指标。

您可以进一步使用 Grafana 可视化您的数据。使用 Grafana PostgreSQL 仪表板创建自定义仪表板 以满足您的需求。

关键词

在此页面上发现问题?报告问题 或 在 GitHub 上编辑此页