How each tenant’s share is worked out
Each day, CostGraph takes the instance’s billed charges and splits them across the databases on it. Databases that your provider runs for its own maintenance, such asrdsadmin on Amazon RDS,
cloudsqladmin on Cloud SQL, and azure_maintenance and azure_sys on Azure, are left out.
CostGraph’s own hourly reads are not counted as activity. On a
day with less than a minute of activity across the instance, CostGraph splits compute by size, the
same as storage. An idle instance is then not charged to the database CostGraph signs in to.
Tenants can also share one database, each signing in with its own role. That database’s compute share
is then split across the roles by their query time.
You tell CostGraph which tenant owns each database or role with a label. The shares add up to the
instance’s bill, so your totals stay the same.
Match your layout to a labelling approach
Instances often mix these layouts. Label each database or role by the approach that fits it.
Before you begin
- The instance’s cost reaches CostGraph on its own line. Connect the billing data for the provider that runs the instance, and check that the bill lists the instance by its resource ID. Some providers only report cost per project or service by default. STACKIT, for example, needs its FOCUS report.
- You know the instance’s resource ID. Use the ID from the instance’s line on the bill, such as its ARN for an instance on AWS. CostGraph splits the cost billed to that ID.
- CostGraph can reach the instance. CostGraph Cloud reaches instances at public addresses only,
and connects with the SSL mode
verify-fullorverify-ca. A self-hosted installation can reach instances on your private network.
Create a login for CostGraph
Create a login that can read usage statistics, and enablepg_stat_statements in the database
CostGraph signs in to:
pg_monitor role lets the login read sizes and activity without reading any table.
pg_stat_statements provides each role’s query time. It must also be listed in the instance’s
shared_preload_libraries. On a managed instance, enable it in your provider’s settings. Without it,
CostGraph still splits the instance by database but cannot split a shared database by role.
If the extension is installed in a schema other than public, let the login use that schema:
Label databases and roles
Tell CostGraph which tenant owns each database or role. You can assign an owner in CostGraph, which needs no access to the instance, or add a comment in PostgreSQL. Use the key you group spend by, such asapp, team, or customer.
Assign an owner in CostGraph
- Open Cost breakdown in the sidebar, select the Showback tab, and select Database allocation.
- Under Group by, choose
postgres:database. To label the roles of a shared database, choosepostgres:role. - Hover over the database or role and select Assign owner.
- Choose the tag key and value, such as
teamandcheckout, and select Assign owner.
Label with a comment
Add akey=value comment that names the tenant:
Connect the instance
- Open Settings > Integrations and pick PostgreSQL.
- Pick the CostGraph tenant whose bill contains the instance, and enter its Instance ID.
- Enter the host, port, database, and the login you created. Choose the SSL mode your instance requires. If its certificate is signed by a private CA, paste the CA certificate.
- Select Connect.
pg_monitor role, a certificate that cannot be verified, and an unreachable
instance. A warning tells you when pg_stat_statements is not enabled, not loaded, or in a schema the
login cannot use, or when the bill has no cost for the instance ID yet.
The connection keeps its warnings, and the reason for any failed hourly read, on the PostgreSQL page
under Settings > Integrations until you fix them.
Connect each shared instance separately. To change the host, port, or login later, enter the password
again.
See each tenant’s share
Open Cost breakdown in the sidebar, select the Showback tab, and select Database allocation. Under Group by, pick the key from your labels, such asapp or customer, to see each tenant’s share
of your shared instances.
To see each database by name, labelled or not, group by postgres:database. Group by
postgres:role to see the roles of a shared database.
Spend that no label claims appears as Unallocated. Label the remaining databases or roles. To
divide a database that tenants share through one login, label it with a shared value and split that
value with a shared cost split.
The Billed layer keeps showing each instance as one line, so your totals do not change.
Fix common problems
- Nothing is split. CostGraph splits from the hour it first reads the instance, so earlier days stay whole. If the connection warns that the bill has no cost for the instance ID, check that the provider’s bill is connected and lists the instance under that ID.
- The connection shows that the instance ID matches several resources. Enter the instance’s full resource ID as it appears on the bill. CostGraph does not split a cost it cannot tie to one instance.
- A shared database is not split by role. Check the warning on the connection. It names whether
pg_stat_statementsis missing, not loaded, or in a schema the login cannot use.