Quick start

Updated at:
Copy as MD

This topic describes how to integrate TSDB with Prometheus.

Prerequisites

  • You must have a purchased or upgraded TSDB instance. If your instance was purchased before April 15, 2019, submit a ticket in the Alibaba Cloud Ticket System to upgrade it.

  • Configure a VPC network.

    • If your Prometheus is deployed on an Alibaba Cloud ECS instance that does not have a VPC network configured, connect the ECS instance to the same VPC network as your TSDB instance. For details, see Network connection.

    • If your Prometheus is deployed outside of Alibaba Cloud, enable public network access for your TSDB instance. For security, you must also configure a network whitelist by requesting a public endpoint for the instance and adding your application's public IP address to it. For details, see Configure a network whitelist.

  • Verify that the host running Prometheus can access the TSDB instance.

    Access the TSDB instance endpoint over HTTP. If the response contains the string "Welcome to use the TSDB", the connection is successful.

Procedure

  1. Install Prometheus.

    This guide uses the pre-compiled binary for a quick deployment.

    Download the binary packages for your operating system from the official Prometheus GitHub repository. The following steps show how to install Prometheus on a Linux system.

    Install 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

    Verify the installation

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

    If the following output appears, the installation is successful:

    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. Configure Prometheus.

    Modify the Prometheus configuration

    This example assumes your TSDB instance has a public endpoint of ts-xxxxxxxxxxxx.hitsdb.rds.aliyuncs.com:3242.

    Add the following content to your prometheus.yaml file.

    # 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
    Note

    In the preceding configuration, read_recent: true instructs Prometheus to read recent data from remote storage. By default, Prometheus always reads recent data from its local storage. If you enable this flag, Prometheus merges data from both local and remote storage. This flag helps verify that remote reads from TSDB are working. In production, you can remove read_recent: true to improve query performance.

    The following example shows a complete prometheus.yaml configuration file:

    # 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
    Important

    The configuration provided here is for this quick start only. For different TSDB instance specifications, best practices are available for Prometheus write configurations to ensure stable data ingestion into TSDB. For details, see Prometheus Remote Write Configuration.

    Start Prometheus

    ./prometheus

    If the following output appears, Prometheus has started successfully:

    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. Verify write and read operations.

    Verify the write operation

    In the TSDB management console, go to the Instance Monitoring page. Initially, the write TPS (transactions per second) is 0. A TPS value greater than 0 confirms that Prometheus is successfully writing data to TSDB.

    Verify the read operation

    The sample configuration in this guide sets Prometheus to monitor itself. To verify the read operation, query one of its own monitoring metrics, such as go_memstats_gc_cpu_fraction. On the Prometheus Graph page, enter this metric name and click Execute. A displayed time series line chart confirms that the read operation is working.