Skip to main content
A shared Cloud SQL instance lands as one line on the bill, even when several services query it. A flat split assigns every consumer the same share. That is a misleading . This walkthrough splits Cloud SQL spend with a Datadog usage metric. You preview the formula in Advanced Explorer, then store the split as a so reports and alerts can reuse it.
Advanced Explorer bar chart with Cost #1, Datadog render.service.cpu.time series, and formula a * b / d allocating Cloud SQL cost

Advanced Explorer preview of shared Cloud SQL cost split with formula a * b / d

Prerequisites

  1. Know what drove the last database cost increase. Use a storage-size metric if storage grew. Use a compute metric if CPU or memory was the constraint.
  2. Know where that usage metric lives, for example Datadog or Google Cloud Monitoring.
  3. Have a Datadog connection under Integrations. This walkthrough uses the demo connection Docs Datadog. To split on a native GCP series instead, connect GCP Cloud Monitoring and pick a Cloud SQL metric such as cloudsql.googleapis.com/database/postgresql/insights/aggregate/execution_time.

What you get

  • Each service’s share of the shared Cloud SQL cost.
  • Recurring reports so stakeholders see the allocated split.
  • Alerts when a service’s share grows unexpectedly.

Steps

1

Choose the usage metric

Select the metric that matches your cost driver. The tabs below are example queries for Datadog and Google Cloud SQL.This walkthrough uses a connected Datadog render metric (render.service.cpu.time) as the compute-style driver, grouped by service.name.Storage-size example queries:
Compute example queries:
2

Connect the metric as an External metric

Go to Integrations, click + Add integration, then under External metric choose Datadog. Do not use Metrics > Import new metrics datasource.
Add integration page showing Billing tiles and an External metric section with Datadog, AWS, GCP, Amplitude, Tsuga, and Google Sheets

Add integration page with the External metric grid, including Datadog

In this walkthrough Docs Datadog is already connected, so you can skip the connect form and query the metric in the next step. If you still need to connect Datadog, follow Datadog metrics, then click Validate and Save connection.
Integrations Data sources list showing Docs Datadog with metrics and metrics_ci badges

Integrations Data sources list with Docs Datadog already connected

3

Add Cloud SQL cost and per-service usage

Try the split in Advanced Explorer before you store it as a virtual dimension. Click Explore your data, then switch to Advanced. Classic only accepts cost metrics.
Query Datadog and other external metrics in Advanced Explorer only.
You will build four series. The formula editor does not support SUM(), so the all-services total is its own series. Add cost and per-service usage here. The next step adds the denominator and the formula.a * b / d is shared Cloud SQL cost times this service’s cpu.time, divided by all services’ cpu.time.Configure Cost #1 (a) as in the table. Open Where and set Service Name In Cloud SQL.
Advanced Explorer Cost #1 row with Where popover set to Service Name In Cloud SQL and a Cloud SQL bar chart

Cost #1 (a) in Advanced Explorer, Where Service Name In Cloud SQL

Click + Add Metric, open integrations, and choose Docs Datadog. Search render, then pick render.service.cpu.time. Set Aggregate to SUM and Group by to service.name.
Advanced Explorer Datadog metric picker searching render and listing render.service.cpu.time

Docs Datadog metric picker searching render, with render.service.cpu.time in the list

Advanced Explorer dual-axis chart of Cloud SQL cost and Datadog render.service.cpu.time grouped by service.name

Cost next to render.service.cpu.time grouped by service.name

Use SUM when you later aggregate this metric at weekly or monthly levels. A maximum aggregation can over-allocate cost to the service that spiked on a single day.
4

Add the usage total and the allocation formula

Click + Add Metric again. Pick the same Docs Datadog metric render.service.cpu.time, Aggregate SUM, Group by None. That series is Externalmetric #4 (d), the denominator.Set Formula #3 (c) to a * b / d. Toggle the checkboxes on each series so you can inspect the allocated series on its own.
Advanced Explorer with Cost a, Datadog series b grouped by service.name, formula a * b / d, and Datadog series d grouped by None

Working allocation formula a * b / d with Externalmetric #4 grouped by None

5

Create a virtual dimension scoped to Cloud SQL

Store the split so you can reuse it in group-bys, reports, and alerts.Go to Dimensions, click + Add new dimension, then Virtual dimension.
Dimensions page Add new dimension menu with Dimension and Virtual dimension options

Dimensions page with Add new dimension open on Virtual dimension

Name it cloud sql reallocated. The modal accepts lowercase letters, numbers, and underscores.
Create a new dimension modal with Name set to cloud sql reallocated

Create a new dimension modal with name cloud sql reallocated

On Rule 1, set the condition Where Service Name In Cloud SQL. That scopes the shared cost this rule reallocates.Open Allocate costs by: and select Dynamic based on usage metric. That is : Costory splits the scoped cost in proportion to the usage series.
Virtual dimension Rule 1 Allocate costs by menu listing Direct value, Split cost, Existing value, and Dynamic based on usage metric

Allocate costs by dropdown with Dynamic based on usage metric

Set Integration to Docs Datadog, Metric to render.service.cpu.time, and Split by to service.name. Aggregate stays SUM.
cloud sql reallocated Rule 1 with Dynamic based on usage metric and the Datadog metric list filtered to render

Rule metric picker on Docs Datadog searching render.service.cpu.time

6

Map metric values and save a draft

Map Datadog service.name values to dimension values. You can use identity pass-through, a regex, or a manual map.
Rule 1 mapping list for costory-app-back and costory-app-back-prod with Select a value dropdowns and Mapping is required

Manual mapping with Select a value for each Datadog service.name

This walkthrough uses identity pass-through: check Set with Regex and keep [\s\S]*. The helper text reads Identity pass-through: metric values are used as dimension values (regex [\s\S]*).
Rule 1 with Set with Regex checked and the pattern that passes metric values through as dimension values

Set with Regex checked, identity pass-through pattern

Completed cloud sql reallocated Rule 1 with Docs Datadog render.service.cpu.time, Split by service.name, and identity regex mapping

Draft rule for cloud sql reallocated using Dynamic based on usage metric

If you choose manual mapping and a new service appears later, edit the virtual dimension to map that service.
Click Save draft. A draft does not appear in Explorer group-by until you Publish. This walkthrough stops at the draft.
The Costory MCP can build this from chat: “draft a virtual dimension that allocates my shared Cloud SQL cost using render.service.cpu.time grouped by service.name, preview it, then save a draft.”
7

Publish and create a report

After you Publish, go to Explorer and create a new report grouped by cloud sql reallocated. You can also schedule the report to Slack on a weekly or monthly basis. See Cost Reports.

Troubleshooting

A draft is not available as a group-by. Open the virtual dimension and click Publish after you finish editing.
The editor does not support SUM() inside a formula. Add the all-services total as its own series (Externalmetric #4) with Group by None, then divide by that series (d).
Identity pass-through picks up new service.name values on the next run. Manual mapping does not. Edit the virtual dimension and map the new label.
Last modified on September 1, 2026