文档

快速入门

更新时间:
一键部署

本文介绍TSDB对接Prometheus方法。

前提条件

  • 已购买(升级)TSDB实例。若2019年4月15日前购买的实例,可通过阿里云工单系统提工单,进行TSDB实例升级。

  • 配置VPC网络。

    • 如果Prometheus部署在阿里云ECS上且没有配置VPC网络,那么可以将PrometheusECS加入到TSDB所在的 VPC网络中,详情请参见网络连接

    • 如果Prometheus部署在非阿里云环境,需要开通TSDB公网,才可以实现网络通信,同时为了保证实例访问安全,需要配置TSDB 实例访问白名单。申请TSDB实例的公网地址,并在网络白名单中填入上述应用环境的公网IP,详情请参见设置网络白名单

  • 确认Prometheus所在机器能够正常访问TSDB实例。

    使用HTTP访问TSDB实例的地址,如果能够得到包含”Welcome to use the TSDB”的字符串,表示Prometheus所在机器能够正常访问TSDB实例。

操作步骤

  1. 安装Prometheus。

    Prometheus用Golang实现,因此具有天然可移植性(支持Linux、Windows、macOS和Freebsd)。这里直接使用预编译的二进制文件部署,开箱即用。

    Prometheus在不同操作系统下的二进制安装包,可以通过Prometheus的GitHub仓库下载,详情请参见GitHub仓库。这里以Linux系统为例进行安装,具体步骤如下。

    Prometheus安装

    wget https://github.com/prometheus/prometheus/releases/download/v2.3.0/prometheus-2.3.0.linux-amd64.tar.gz
    tar -zxvf prometheus-2.3.0.linux-amd64.tar.gz
    mv prometheus-2.3.0.linux-amd64 /usr/local/prometheus

    验证安装

    cd /usr/local/prometheus/
    ./prometheus --version

    若出现以下信息,表示安装成功

    prometheus, version 2.3.0 (branch: HEAD, revision: 290d71791a507a5057b9a099c9d48703d86dc941)
      build user:       root@d539e167976a
      build date:       20180607-08:46:54
      go version:       go1.10.2

  2. 配置Prometheus。

    修改Prometheus配置

    以TSDB实例的公网地址为ts-xxxxxxxxxxxx.hitsdb.rds.aliyuncs.com:3242为例。

    在prometheus.yaml中添加以下内容。

    # Remote write configuration (TSDB).
    remote_write:
      - url: "http://ts-xxxxxxxxxxxx.hitsdb.rds.aliyuncs.com:3242/api/prom_write"
    
    # Remote read configuration (TSDB).
    remote_read:
      - url: "http://ts-xxxxxxxxxxxx.hitsdb.rds.aliyuncs.com:3242/api/prom_read"
        read_recent: true
    说明

    上面的配置中,“read_recent: true”表示近期数据也要读远程存储。因为Prometheus近期数据无论如何都是要读本地存储的,如果开启这个标志位,Prometheus会把本地和远程的数据进行Merge。开启这个标志位,可以方便验证读取远程TSDB是否正常工作。如果正式在生产环境,可以根据实际情况将“read_recent: true”去掉,可提升Prometheus的查询性能。

    Prometheus完整的示例配置如下所示。

    # my global config
    global:
      scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
      evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
      # scrape_timeout is set to the global default (10s).
    
    # Alertmanager configuration
    alerting:
      alertmanagers:
      - static_configs:
        - targets:
          # - alertmanager:9093
    
    # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
    rule_files:
      # - "first_rules.yml"
      # - "second_rules.yml"
    
    # A scrape configuration containing exactly one endpoint to scrape:
    # Here it's Prometheus itself.
    scrape_configs:
      # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
      - job_name: 'prometheus'
    
        # metrics_path defaults to '/metrics'
        # scheme defaults to 'http'.
    
        static_configs:
        - targets: ['localhost:9090']
    # Remote write configuration (TSDB).
    remote_write:
      - url: "http://ts-xxxxxxxxxxxx.hitsdb.rds.aliyuncs.com:3242/api/prom_write"
    
    # Remote read configuration (TSDB).
    remote_read:
      - url: "http://ts-xxxxxxxxxxxx.hitsdb.rds.aliyuncs.com:3242/api/prom_read"
        read_recent: true
    注意

    这里的配置仅仅是快速入门用,针对不同规格的TSDB实例,我们提供了Prometheus写入配置的最佳实践,用于实现Prometheus平稳的将监控样本数据写入TSDB,详情请参考Prometheus Remote Write配置的内容。

    启动Prometheus

    ./promtheus

    若出现以下信息,则表示启动成功。

    level=info ts=2019-04-15T10:39:12.870828882Z caller=main.go:222 msg="Starting Prometheus" version="(version=2.3.0, branch=HEAD, revision=290d71791a507a5057b9a099c9d48703d86dc941)"
    level=info ts=2019-04-15T10:39:12.870926993Z caller=main.go:223 build_context="(go=go1.10.2, user=root@d539e167976a, date=20180607-08:46:54)"
    level=info ts=2019-04-15T10:39:12.870971602Z caller=main.go:224 host_details="(Linux 4.9.93-010.ali3000.alios7.x86_64 #1 SMP Fri Apr 20 00:18:51 CST 2018 x86_64 common-dev100081116006.eu95sqa (none))"
    level=info ts=2019-04-15T10:39:12.871010623Z caller=main.go:225 fd_limits="(soft=655350, hard=655350)"
    level=info ts=2019-04-15T10:39:12.872103134Z caller=main.go:514 msg="Starting TSDB ..."
    level=info ts=2019-04-15T10:39:12.87214458Z caller=web.go:426 component=web msg="Start listening for connections" address=0.0.0.0:9090
    level=info ts=2019-04-15T10:39:12.877363461Z caller=main.go:524 msg="TSDB started"
    level=info ts=2019-04-15T10:39:12.877417508Z caller=main.go:603 msg="Loading configuration file" filename=prometheus.yml
    level=info ts=2019-04-15T10:39:12.879382462Z caller=main.go:500 msg="Server is ready to receive web requests."
  3. 写入和读取验证。

    写入验证

    通过TSDB实例的管理控制台界面的实例监控界面,观察写入的TPS是否有所变化来验证。刚开始没有任何数据写入时,写入的TPS为0,当TPS开始从0变为正数时,则说明Prometheus已经将数据上报到了TSDB中。Image 23

    查询验证

    本文提供Prometheus的示例配置中Prometheus监控指标采集目标是prometheus本身,因此这里以Prometheus采集到自身的一个监控指标“go_memstats_gc_cpu_fraction”为例进行查询认证,结果如下图所示。p332186

  • 本页导读 (1)
文档反馈