This document takes a deeper look at Metronome's concept of billable metrics, which aggregate customer usage. Billable metrics are tracked continuously as usage enters the system, so they can power real-time usage dashboards and alerting. They also form the basis for pricing.
Usage enters the system in the form of usage events, which are covered in the Getting usage data into Metronome guide.
An example web hosting company might have two types of usage events: one for each incoming HTTP request and one for an hourly snapshot of disk usage. The rest of this document will use these example events:
A billable metric describes a per-customer aggregation over a subset of usage events. The following would be reasonable billable metrics to build on top of these usage events:
- number of page hits:
- total amount of data transferred:
- maximum data on disk:
As in this example, it's common for a single usage event to be the basis for multiple billable metrics. Each metric specifies an aggregator and, with the exception of
count, a single property to aggregate over. Metronome currently supports the following aggregators: count, sum, max, and unique (which counts the number of unique values).
Flexible event filtering
In the preceding example, each billable metric applied to all events with a given
event_type. It can sometimes be useful to define more complex filters. Perhaps our example web hosting company only wants to track data transfer for successful HTTP requests. The following updated billable metric would support this:
page_load events where
For now, you'll need to work with a Metronome engineer to set up your billable metrics. They can guide you on what type of filtering is possible.
When defining a billable metric, you can also specify one or more properties the metric should be grouped by. This functions similarly to a
group by clause in a SQL query. Grouping a metric by a property does not affect pricing, but the grouping is available in the
/usage API endpoint, and it can be used to alter the appearance of products on an invoice.
Continuing the web hosting example, grouping by the
region property would support giving customers a breakdown of how each region contributed to their overall traffic, as in the following example API request and response:
POST /v1/customers/<customer ID>/billable-metrics/<metric ID>/usage HTTP/1.1
Authorization: Bearer TOKEN
"values": ["US-East, US-West, EU-Central"]
HTTP/1.1 200 OK
For performance reasons, we recommend having no more than 100 unique values for a property you're grouping by.
If you haven't already, read Getting usage data into Metronome to see how to make sure the usage events you're sending Metronome support the billable metrics you want to define. Work with your Metronome representative to create your billable metrics and start aggregating usage.
Once your billable metrics are created, you can use them to configure products and pricing.