🎉 Announcing our $3 million seed round
Logo
Getting Started

Postgres

OpenMeter can integrate with your Postgres database to collect usage data directly from your database. By leveraging your existing data source for usage metering, you can significantly decrease the upfront cost of changing your data collection strategy.

This is a Benthos-based collector.

Configuration

First, create a new YAML file for the collector configuration. You will have to use the sql_select Benthos input:

input:
  sql_select:
    driver: postgres
    dsn: 'postgres://[user[:password]@][netloc][:port][/dbname][?param1=value1&...]'
    table: YOUR_TABLE
    columns:
      - id
      - data_column
      - subject_column
      - time
    where: time >= ?
    args_mapping: root = [ now().ts_unix() - 30 ]

The above section will tell Benthos how to read data from your database.

Next, you need to configure the mapping from your database schema to CloudEvents using bloblang:

pipeline:
  processors:
    - mapping: |
        root = {
          "id": this.id,
          "specversion": "1.0",
          "type": "your-usage-event-type",
          "source": "postgres",
          "time": this.time,
          "subject": this.subject_column,
          "data": {
            "data": this.data_column,
          },
        }

Finally, you need to configure the OpenMeter output:

output:
  openmeter:
    url: https://openmeter.cloud # optional
    token: '<YOUR OPENMETER CLOUD TOKEN>'

Read more about configuring Benthos in the Benthos-based collector guide.

Installation

Check out the Benthos-based collector guide for installation instructions.

Last edited on May 8, 2024