Step 3: Define billable metrics

Zenskar's billable metrics allow you to aggregate and interpret the raw usage data collected from your client's system. This step involves defining how specific fields from your usage events (like cpu_hours_consumed or storage_gb_month) are aggregated over time to form billable quantities.


Prerequisites


Define billable metrics

The visual query builder provides a guided interface to define your billable metrics by selecting data tables and applying aggregation logic.

  1. Log in to your Zenskar dashboard.
  2. Navigate to Usage > Billable Metrics.
  3. Click ADD NEW BILLABLE METRIC and choose the VISUAL BUILDER option.
  4. Use the Visual Builder to create billable metrics:

First metric: For CPU usage

  • Tab 1: Select tables and filters
    • In the Select data table section, use the Table Name dropdown. Select compute_events (the usage event you defined in step 2.1 for CPU usage).
    • (Optional: Use + Add Filter if you need to filter events before aggregation, e.g., by region).
  • Tab 2: Map customer
    • Click NEXT to proceed to the Map customer screen.
    • Under Your customer column, select customer_id. This is the field from your compute_events that identifies the customer in your system.
    • Under Zenskar customer column, select external_id. This maps ACME Inc.'s Id in your system to the Zenskar customer's unique external Id.
  • Tab 3: Set date field
    • Click NEXT to proceed to the "set date field" screen.
    • Under "column", select timestamp. This maps the timestamp from your compute_events as the primary date field for aggregation.
  • Tab 4: Set billable metric over
    • Click NEXT to proceed to the "set billable metric over" screen.
    • Under Select calculation type, choose SUM (as opposed to COUNT) to sum up the values.
    • Under Select column to calculate over, choose data.cpu_hours_consumed.
    • Click CREATE BILLABLE METRIC. Give your metric a name (e.g., Total CPU Hours).

Second metric: For storage usage

Repeat the process by clicking "add billable metric" and selecting "visual builder" again.

  • Tab 1: Select tables and filters
    • In the "select data table" section, choose storage_events (the usage event you defined in step 2.1 for storage usage).
    • Ensure the "usage event" checkbox is marked.
  • Tab 2: Map customer
    • Map the customer_id field from your storage_events to the external_id in Zenskar.
  • Tab 3: Set date field
    • Map the timestamp field from your storage_events.
  • Tab 4: Set billable metric over
    • Select calculation type: Choose SUM.
    • Select column to calculate over: Choose data.storage_gb_month.
    • Click CREATE BILLABLE METRIC. Give your metric a name (e.g., Total Storage GB-Months).