# Cost Tracking

> Source: https://parallelworks.com/docs/kubernetes/cost-tracking

# Cost Tracking

ACTIVATE can track per-namespace compute costs on your Kubernetes clusters. When enabled, a cost-tracking agent runs inside the cluster, periodically sampling CPU and memory usage for every pod. These samples are combined with configurable pricing rates to produce cost records broken down by namespace.

## Enabling Cost Tracking

To enable cost tracking for a cluster:

1. Navigate to **Kubernetes** in the sidebar and open the **Cost Management** drawer.
2. Select the cluster from the **Cluster Name** dropdown.
3. Click **Enable Cost Tracking**.
4. Confirm the prompt — this will deploy new pods to the cluster to collect cost data.

The cluster's cost tracking status will change to **Provisioning** while the agent is being deployed. Once the agent is running, the status changes to **Enabled**.

:::info Cluster Requirement
Enabling cost tracking deploys a cost-tracking agent as pods inside the target cluster. The agent requires the Kubernetes Metrics Server to be available on the cluster.
:::

## Status Indicators

The cost tracking status for a cluster is displayed next to the cluster name in the Cost Management drawer. Possible statuses are:

| Status | Meaning |
|--------|---------|
| **Enabled** | Cost tracking is active and collecting data |
| **Disabled** | Cost tracking is not running on this cluster |
| **Provisioning** | The cost-tracking agent is being deployed to the cluster |
| **Deleting** | The cost-tracking agent is being removed from the cluster |

Click the status indicator to view detailed provisioning steps and progress.

## Configuring Pricing

Once cost tracking is enabled, you can set custom pricing rates that determine how resource usage is converted into cost values. Two rates are configurable:

| Rate | Description | Default |
|------|-------------|---------|
| **CPU Price** (per core/min) | Cost charged per vCPU core per minute of usage | $0.00055 |
| **Memory Price** (per GB/min) | Cost charged per GiB of memory per minute of usage | $0.00007 |

To update pricing:

1. Open the **Cost Management** drawer and select the cluster.
2. Enter new values in the **CPU Price** and **Memory Price** fields.
3. Click **Update Prices**.

The new rates are sent to the cost-tracking agent running on the cluster and take effect immediately for all future cost calculations.

:::tip Pricing Guidance
Set prices to match your infrastructure costs. For cloud-hosted clusters, you can derive per-core and per-GiB minute rates from your cloud provider's pricing for the instance types in your node pools.
:::

## How Costs Are Calculated

The cost-tracking agent samples resource data at regular intervals. For each sampling interval, costs are calculated as follows:

### 1. Collect Pod-Level Usage and Requests

For every pod in every namespace, the agent collects:

- **CPU usage** — actual CPU cores consumed (from the Metrics Server)
- **CPU requests** — CPU cores reserved in the pod spec
- **Memory usage** — actual bytes of memory consumed (from the Metrics Server)
- **Memory requests** — bytes of memory reserved in the pod spec

### 2. Determine Billable Resources

For each pod, the billable amount for each resource is the **greater of usage or requests**:

```
billable_cpu    = max(cpu_usage, cpu_requested)
billable_memory = max(memory_usage, memory_requested)
```

This means you are charged for at least what you requested, even if actual usage is lower. If usage exceeds the request, you are charged for the higher actual usage.

### 3. Aggregate by Namespace

Billable CPU and memory values are summed across all pods within each namespace. This produces a single CPU (in cores) and memory (in GiB) total per namespace per sampling interval.

### 4. Apply Pricing Rates

The final cost for each namespace is:

```
cpu_cost    = billable_cpu_cores * cpu_price_per_core_per_minute
memory_cost = billable_memory_gib * memory_price_per_gib_per_minute
total_cost  = cpu_cost + memory_cost
```

Each cost record is stored with a timestamp and the namespace (group) it belongs to.

:::info Memory Units
Memory values are collected in bytes and converted to GiB (divided by 1024^3) before pricing is applied.
:::

## Disabling Cost Tracking

To disable cost tracking for a cluster:

1. Open the **Cost Management** drawer and select the cluster.
2. Click **Disable Cost Tracking**.
3. Confirm the prompt.

:::warning Data Loss
Disabling cost tracking **removes all collected cost data** for the cluster. This action cannot be undone. If you need to retain historical cost data, export it before disabling tracking.
:::

The status will change to **Deleting** while the cost-tracking agent pods are removed from the cluster. Once removal is complete, the status returns to **Disabled**.

## See Also

- [Resource Quotas](/docs/kubernetes/resource-quotas) — set CPU, memory, and GPU limits per namespace
- [Workload Metrics](/docs/kubernetes/workload-metrics) — monitor real-time resource usage for individual workloads
