Tutorial: Calculate Unit Cost By Creating a Telemetry Stream
Introduction
Suppose you work at a food delivery company called EatIn. You've connected your cloud provider account to CloudZero, and now you want to determine how best to optimize your cloud costs, as described in What Is Cloud Unit Economics (CUE)? A Comprehensive And, More Importantly, Fun Guide. One way to do that is by calculating a unit cost: a system of using objective measurements to ensure your business is maximizing profit when delivering and developing cloud-based software and services.
To define a unit cost, you calculate consumption divided by demand driver.
In this case, the consumption is your cloud spend for operating EatIn. The demand driver is the number of orders EatIn processes. So, one unit cost you can track is cost per order.
Suppose you have created a custom dimension to allocate your cloud costs by engineering team as well. You can combine your custom dimension with the cost per order unit metric to determine a second unit metric, cost per order per engineering team.
This tutorial walks you through how to calculate unit costs with CloudZero. In this guide, you'll take the following steps:
- Prepare a CSV file containing cloud usage data. In this tutorial, we provide the example CSV file for you.
- Upload the CSV to create a unit cost telemetry stream to send cloud usage data to CloudZero.
- Create an Analytics dashboard to calculate and display your cost per order per engineering team unit cost.
Completing this simple tutorial will take about 10 minutes. You can take a break during the process while CloudZero loads the unit cost telemetry stream with data from your cloud provider.
Methods of Sending Data to CloudZero
There are three methods of sending unit cost telemetry data to CloudZero:
- Import a CSV through the CloudZero UI.
- Send a
POST
request to the /unit-cost/v1/telemetry/metric/{metric_name}/sum API endpoint. - Email a CSV to the CloudZero team. Note that email is sent in plaintext, so be mindful of attaching sensitive data. Consider emailing us a link through an encrypted file-sharing service.
This tutorial focuses on the first method, importing a CSV.
Prerequisites
- A CloudZero account with the Organizer role.
- An existing cloud provider connection in CloudZero (for example, AWS, Azure, or Google Cloud).
- An existing custom dimension named
Engineering Team
to track spending by engineering team. To learn how to create a custom allocation dimension, see Allocation Dimensions. - Usage data to calculate the unit cost with. In this example, we provide a sample CSV with the number of orders attributed to each engineering team for the month of September 2024.
This example uses a custom dimension to demonstrate how to refine a unit cost, but you can create a simple unit cost without allocation. For example, if you just wanted to determine cost per order, you would not need to define a custom dimension.
Step 1: Prepare the Data
An important part of preparing the data is determining which demand driver to track and then collecting its relevant data from system logs, sales systems, or anywhere else the data is sourced.
The demand driver will differ for every organization, but you can learn more about demand drivers in the What Is Cloud Unit Economics? guide. For more information about gathering demand driver data, see Common Sources of Unit Cost Telemetry Data.
For this example, we've decided to track the number of orders processed by the fictional company EatIn, and we've already gathered the data for you from EatIn's application logs.
Download this tutorial's example CSV file containing the data required to calculate the unit cost.
The example CSV includes the following columns:
- Date
- Number Of Orders
- Engineering Team
Only a timestamp column and unit value column are required when creating a unit cost telemetry stream. However, because we intend to filter the costs by engineering team in this example, the file also includes a column where each value is a specific engineering team name. These values match the elements defined in the Engineering Team
dimension.
Here are the first few rows of the example CSV:
Date,Engineering Team,Number Of Orders
2024-09-01,Leonardo,2717
2024-09-01,Raphael,2779
2024-09-01,Michelangelo,6242
2024-09-01,Donatello,3451
In summary, each row in the CSV represents the number of EatIn orders associated with an engineering team for each day in September 2024.
For example, on September 1, 2024, Team Leonardo was responsible for 2,717 orders.
Step 2: Upload the CSV to CloudZero
The next step is to create the unit cost telemetry stream by uploading the CSV to CloudZero.
Log in to CloudZero and navigate to Settings > Telemetry Streams, then select Create New Stream > New Unit Cost Stream.
Enter a stream name. For this example, use the name engineering-team-orders
. Be aware that you can't change the name after creating the stream, so ensure it is correct. Otherwise, you'd need to delete the stream and create a new one with the correct name.
Next, enter the stream description: Number of orders per engineering team per day
. You can change this later from the stream details page, if needed.
In the Upload CSV section, set the Granularity. A telemetry stream's granularity determines how you track data changes over a period of time. Because the goal is to track changes between orders from day to day, choose Daily (which is the default).
Next, select the example_data.csv
file or drag and drop it into the Upload CSV File field. Note that the maximum file size is 3MB.
In the Timestamp section, select Date from the drop-down menu. This uses the Date
column in the CSV to set the date for each record in the telemetry stream.
In the Unit value section, select Number of Orders from the drop-down menu. This uses the Number of Orders
column to set the unit value for each record in the telemetry stream -- the number of orders per engineering team per day.
Now, set the Target Dimension (Optional) drop-down to the Engineering Team
custom dimension you created as a prerequisite to this tutorial. This associates each engineering team with its number of orders per day, which allows you to allocate cloud cost per order by the Engineering Team dimension.
Set the Dimension Element drop-down menu to the column containing each element (team name) in your dimension. This is the Engineering Team
column in the sample CSV. The column name does not need to match the dimension -- you can, in fact, name the column anything you like -- but we've kept it the same as the dimension name in this example for clarity.
Now that you've configured the unit cost telemetry stream, the stream creation page should look like this:
Review the CSV Reference Table to make sure it displays as you expect it to:
Finally, select the Save button:
CloudZero redirects you to the Telemetry Streams page and creates a unit cost telemetry stream according to your specifications.
Now, select the newly created stream to view its details page.
It can take up to 24 hours for CloudZero to ingest the data for a new telemetry stream, depending on the size of data. Smaller files can be ingested more quickly. While CloudZero processes the data, the details page will look as follows, with the Status displayed as Pending
:
You can additionally see the following information on the details page:
- Stream name and description
- Type of stream (
Metric
) - Granularity (
Daily
) - Source (
CSV
) - Targeted dimensions (
Engineering Team
) - Activity graph
- Last request timestamp
- Start date timestamp
- Recent errors
After CloudZero has finished ingesting the initial stream data, you can hover over the activity graph to see the number of records, requests, and errors processed per day:
Step 3: Create a Dashboard
When the stream's ingest status is shown as Available, you can create an Analytics dashboard by navigating to Analytics and selecting Create Dashboard.
Enter the name Cost Per Order Per Engineering Team, and set the visibility to either public (viewable by everyone in your organization) or private.
On the empty dashboard, select the Add button, and then select Visualization from the drop-down menu.
In the Choose an Explore window, select CloudZero Billing Data from the list on the left, underneath your organization ID:
Replace Untitled
with the name you plan to use for your visualization: Cost Per Order Per Engineering Team Per Day
.
Next, select the desired dimensions and measures to visualize them. Our goal is to show the unit cost per order per engineering team, so expand the field list and select the following fields:
- Cost Types & Usage > Real Cost
- Custom Dimensions > Engineering Team
- Unit Metrics > Engineering Team Orders
Then, select Add calculation:
The Create table calculation modal is where you define the custom expression to calculate the cost per order by engineering team, so you can display it in the visualization. To do this, you instruct CloudZero to divide the total cloud cost by the unit cost, as follows:
- In the Expression field, start typing
base_billing_data.real_cost
and select the Real Cost ${base_billing_data.real_cost} row that appears in the drop-down menu. - Add a
/
to indicate division. - Start typing the name of the unit cost telemetry stream,
engineering_team_orders
, and select the engineering_team_orders_12345678901234567890123456789012_unit_metric.metric dimension that appears in the drop-down menu. (Note that the hyphens in the original telemetry stream name are replaced by underscores, so you'll need to use underscores when you type the stream name.) - Set Format to U.S. Dollars and Decimals to 2.
- Enter a name in the Name field.
The expression should look like the following, though your telemetry stream name will be followed by a different ID:
${base_billing_data.real_cost}/${engineering_team_orders_12345678901234567890123456789012_unit_metric.metric}
Select Save to save the custom expression.
Back in the visualization editor, select the column icon from the Visualization bar to display the chart as a series of columns:
For the chart to be most useful, you can configure it to display only the unit cost and the engineering team. Hide the Unit Metric Engineering Team Orders and Cost Types & Usage Real Cost columns from the visualization by selecting the cog icon next to each one's name and selecting Hide this field in visualization:
Finally, select Save. You'll see the new chart on your dashboard:
If you like, you can add more visualizations to further customize your dashboard. When you're done, select Save to save the dashboard.
Next Steps
If you need to add new data or update existing data in your telemetry stream, you can upload another CSV. For example, you might decide to add order data for October 2024. Alternatively, you can send data to the CloudZero API.
Further Reading
To learn more about unit cost metrics, see the following documentation:
Updated 12 days ago