Using TimescaleDB to store Prometheus data

You can persist prometheus metrics into timescaledb with promscale.

You can use postgres as the remote storage database used by the Prometheus backend.

While this is not the recommended behavior, it is a good opportunity to understand how the Pigsty deployment system is used.

Preparing the Postgres database

  1. vi pigsty.yml # Uncomment DB/User definition: dbuser_prometheus prometheus
  2. pg_databases: # define business users/roles on this cluster, array of user definition
  3. - { name: prometheus, owner: dbuser_prometheus , revokeconn: true, comment: prometheus primary database }
  4. pg_users: # define business users/roles on this cluster, array of user definition
  5. - {name: dbuser_prometheus , password: DBUser.Prometheus ,pgbouncer: true , createrole: true, roles: [dbrole_admin], comment: admin user for prometheus database }

Create a Prometheus business database with business users.

  1. bin/createuser pg-meta dbuser_prometheus
  2. bin/createdb pg-meta prometheus

Check database availability and create extensions。

  1. psql postgres://dbuser_prometheus:DBUser.Prometheus@10.10.10.10:5432/prometheus -c 'CREATE EXTENSION timescaledb;'

Configure Promscale

Install promscale by executing the following command on the meta node

  1. yum install -y promscale

If not available in the default package, you can directly download it.

  1. wget https://github.com/timescale/promscale/releases/download/0.6.1/promscale_0.6.1_Linux_x86_64.rpm
  2. sudo rpm -ivh promscale_0.6.1_Linux_x86_64.rpm

Edit the promscale config file /etc/sysconfig/promscale.conf.

  1. PROMSCALE_DB_HOST="127.0.0.1"
  2. PROMSCALE_DB_NAME="prometheus"
  3. PROMSCALE_DB_PASSWORD="DBUser.Prometheus"
  4. PROMSCALE_DB_PORT="5432"
  5. PROMSCALE_DB_SSL_MODE="disable"
  6. PROMSCALE_DB_USER="dbuser_prometheus"

Finally start promscale, which will access the database instance with timescaledb installed and create the required schema.

  1. # launch
  2. cat /usr/lib/systemd/system/promscale.service
  3. systemctl start promscale && systemctl status promscale

Configure Prometheus

Prometheus can use Remote Write/ Remote Read via Promscale, using Postgres as remote storage.

Edit Prometheus config file.

  1. vi /etc/prometheus/prometheus.yml

Add the following record.

  1. remote_write:
  2. - url: "http://127.0.0.1:9201/write"
  3. remote_read:
  4. - url: "http://127.0.0.1:9201/read"

After restarting Prometheus, the monitoring data can be placed in Postgres.

  1. systemctl restart prometheus

Last modified 2022-06-03: add scaffold for en docs (6a6eded)