Launch week is here! March 17, 2025
Logo

Prometheus

OpenMeter Collector can query Prometheus to collect metrics for billing and invoicing. This is useful for companies using Prometheus to monitor their infrastructure and want to bill and invoice their customers based on already collected metrics.

How it works

OpenMeter periodically queries your Prometheus instance using PromQL queries and emits the results as CloudEvents to your OpenMeter instance. This allows you to track usage and billing for your Prometheus workloads.

Sending Prometheus metrics into OpenMeter as billing events also helps to have an auditable record of the billing events as most Prometheus instances keep metrics only for a short period of time while OpenMeter can keep the billing events for a long time, providing a record of the usage and billing for auditing and accounting purposes.

Examples

For example if you already have a Prometheus metrics about the number of API requests your application serving for your customers, you can use the OpenMeter Collector to turn the Prometheus metrics into billable events and send them to OpenMeter for billing.

Billing from Prometheus Metrics?

Re-using existing Prometheus metrics can save you a lot of time and effort. But be aware that Prometheus metrics are not designed for billing and can lead inaccuracies due to the following reasons:

  • Metrics can be lost when the app restarts and the metrics wasn't collected by the Prometheus scraper.
  • Metrics are not deduplicated, so you can get multiple metrics for the same event.

For these reasons, we recommend using Prometheus metrics for billing only for long running workloads where the impacts of these inaccuracies is insignificant on the total bill.

Getting Started

Powered by Redpanda Connect

First, create a new YAML file for the collector configuration. You will have to use the prometheus Redpanda Connect input:

input:
  prometheus:
    # Prometheus server URL the collector will query
    url: '${PROMETHEUS_URL}'
    # Scrape interval for the collector, e.g. once per minute
    schedule: '0 * * * * *'
    # Time offset for queries to account for delays in metric availability
    query_offset: '1m'
    # List of PromQL queries to execute
    queries:
      - query:
          # Unique identifier for the query results
          name: 'node_cpu_usage'
          # PromQL query to execute
          promql:
            # [1m] is the query interval for the query, keep in sync with the collector's schedule
            sum(increase(node_cpu_seconds_total{mode!='idle'}[1m])) by
            (instance)
Keep Query Interval in Sync

Be sure to keep the collector's schedule interval in sync with the PromQL interval. If the query interval is not for the same period as the collector runs for you can miss or double collect metrics.

The above section will tell Redpanda Connect how to query metrics from your Prometheus instance.

Configuration Options

OptionDescriptionDefaultRequired
urlPrometheus server URL-Yes
scheduleCron expression for the scrape interval0 * * * * *No
query_offsetTime offset for queries to account for delays in metric availability0sNo
queriesList of PromQL queries to execute-Yes

Each query in the queries list requires a name (unique identifier for the query results) and a promql expression to execute.

Next, you need to configure the mapping from the Prometheus metrics to CloudEvents using bloblang:

pipeline:
  processors:
    # Map each value to a separate message with name, timestamp, and value
    - mapping: |
        root = this.values.map_each(value -> {
          "id": uuid_v4(),
          "specversion": "1.0",
          "type": this.name,
          "source": "prometheus",
          "time": this.timestamp,
          "subject": value.metric.instance,
          "data": {
            "value": value.value,
            "metric": value.metric
          }
        })
    # Convert JSON array to individual messages
    - unarchive:
        format: json_array

Finally, you need to configure the OpenMeter output:

output:
  label: 'openmeter'
  http_client:
    url: '${OPENMETER_URL:https://openmeter.cloud}/api/v1/events'
    verb: POST
    headers:
      # Optional: API key for OpenMeter Cloud
      Authorization: 'Bearer ${OPENMETER_TOKEN:}'
      Content-Type: 'application/json'
    # Batch settings for efficient API usage
    batching:
      # Send up to 100 events in a single request
      count: 100
      # Or send after 1 second, whichever comes first
      period: 1s
      processors:
        # Convert batch to JSON array format
        - archive:
            format: json_array
    dump_request_log_level: DEBUG

Read more about configuring Redpanda Connect in the OpenMeter Collector guide.

Scheduling

The collector runs on a schedule defined by the schedule parameter using cron syntax. It supports:

  • Standard cron expressions (e.g., 0 * * * * * for once per minute)
  • Duration syntax with the @every prefix (e.g., @every 1m)

Query Offset

The query_offset parameter allows you to query for data from a point in the past, which is useful when metrics have a delay before they're available in Prometheus. For example, setting query_offset: "1m" means each query will be executed against data from 1 minute ago.

Installation

Check out the OpenMeter Collector guide for installation instructions.