# Calculations

In this section we review metrics and calculations provided on the Replex dashboards.

Here is a list of all the calculations described in this section:

* Forecasted cost
* Cost previous 30 days
* Total cost
* Idle cost
* Savings
* Utilized cost
* Cluster score
* CPU
* RAM
* Storage
* Attached Node Disks

### Forecasted Cost&#x20;

**Next 30 days forecast** is a prediction of the next month’s costs based on the historical data of the past 7 days.

![Next 30 days forecast](/files/-MFf2OyoIsY7F-RZZSOq)

### Costs previous 30 days&#x20;

**Costs previous 30 days** are the total costs of the cluster resources (VM instances, storage) for the past 30 days.

![](/files/-MFf2lcts4QpR9YEfWdx)

### Total cost&#x20;

**Total Cost** is calculated as the sum of **Idle Cost** and **Utilized Cost**.

For example **Cluster Total cost** is calculated as the sum of **Idle Cost** and **Utilized Cost** of all resources in that cluster.&#x20;

![Cluster Total Cost](/files/-MFf39rJ911ugKWwspTF)

**Namespace Total cost** is calculated as the sum of **Idle Cost** and **Utilized Cost** for all pods running in that Namespace.

![Namespace Total cost](/files/-MFf64FhhnUcZ03pT2gA)

Similarly, **Team Total cost** is calculated as the sum **Idle Cost** and **Utilized Cost** for all pods labelled with that specific team.

![Team Total cost](/files/-MFf66UG9w7mj6h3ku0a)

### **Idle cost**

**Cluster Idle cost** is calculated as the total cost of cluster resources that are unused.

```
idle cluster cost = idle CPU cost + idle RAM cost + idle PVC cost
```

In the above calculation the **Idle CPU cost** is a sum of idle CPU cost for all nodes belonging to the cluster. Similarly the **Idle RAM cost** is a sum of idle RAM cost for all nodes belonging to that cluster.

![Cluster Idle cost](/files/-MFf39rJ911ugKWwspTF)

**Node Idle CPU cost** is calculated as the cost of un-utilized CPU on that node.

```
Node idle CPU cost = cost of un-utilized node CPU
```

Similarly **Node idle RAM cost** is calculated as the cost of un-utilized RAM on that node.

```
Node idle RAM cost = cost of un-utilized node RAM
```

Lastly, **Node idle PVC cost** is calculated as the cost of un-utilized Persistent Volume Storage provisioned for that cluster.&#x20;

```
idle PVC cost = cost of un-utilized Persistent Volume Storage
```

### Savings&#x20;

**Cluster Savings** represent the cost savings that can be made by optimising cluster resource utilization. &#x20;

![Savings](/files/-MFf39rJ911ugKWwspTF)

On the Replex UI **Cluster** **Savings** are calculated as the deviation of the **total cluster cost** from a best practice utilization baseline of 70%.

```
Cluster Savings = total cluster costs - (used costs / 0.7)
```

Here is an example to make this clearer:

Assume we have a cluster with a **total cluster cost** of $100 and used costs of $25. In this scenario cluster savings are calculated as follows:

```
Cluster Savings = $100 - ($25 / 0.7) = $64.29
```

This means that cluster costs can be reduced by $64.29, with a cluster utilization of 70%.

Once optimised, the new cluster cost is $35.71.

```
New cluster cost = $100 - $64.29 = $35.71
```

Similarly, the new cluster utilization is 70.01%

```
New cluster utilization = $25 / $35.71 * 100 = 70.01%
```

### Utili**z**ed cost&#x20;

**Utilized Cost** is calculated as the sum of **Pod CPU cost**, **Pod RAM cost** and **Storage cost** for all pods.

For example **Namespace Utilized costs** are calculated as the sum of **Pod CPU cost**, **Pod RAM cost** and **Storage cost** for all pods running in that namespace.

![Namespace Utilized cost](/files/-MFf6ZkugbWQ7Ehe1vWE)

Similarly, **Team Utilized costs** are calculated as the sum of **Pod CPU cost**, **Pod RAM cost** and **Storage cost** for all pods labelled with that specific team.

![Team Utilized cost](/files/-MFf6gTW5HTGg0DNvu_n)

### Cluster score&#x20;

**Cluster score** is calculated based on how much resources were used within the cluster. The efficiency score is the deviation of actually used resources from the expected resources baseline.

![Cluster score](/files/-MFf4yqmDGBhtEEtYWW7)

```
Expected resources baseline = used resources (100 - 30)% = 70% 
```

where **30%** is allowed idle cost.

#### Example

If used resources are **58%** of total cost:

```
efficiency score = (1 - ((70 - 58) / 70)) * 100 = 83%
```

Note, that if used resources go above the requested resources, the efficiency will not exceed 100%, instead the idle costs will increase.

#### Efficiency Score in the Replex Interface

The icon next to the efficiency score is displayed in different colours, based on the actual score value. This ensures a quick overview of the general efficiency of the cluster, wether it is in the cluster list or on the cluster dashboard.

![](/files/-MFf5C1H_esjg-Bjv8E2)

A score between 61 and 100 means that the available cluster resources are used in an efficient way.

![](/files/-MFf5EFWB-AFj-ZDoNMR)

A score between 31 and 60 means that the cluster configuration should be improved.

![](/files/-MFf5GArRcaVQBPNSAGR)

A score between 0 and 30 means that most of the resources in the cluster are idling and the cluster should be downscaled in order to safe money.&#x20;

### CPU&#x20;

**Pod Requested CPU** is calculated as the sum of CPU requests for all containers in the pod.&#x20;

![Pod Requested CPU](/files/-MFf9PYKLsocbVpp-k4K)

Each container can request CPU resources either as a fraction (0.5) or as millicpu (500m) using `spec.containers[].resources.requests.cpu`

In Kubernetes one CPU is equivalent to 1 vCPU/Core for cloud providers and 1 hyperthread on bare-metal Intel processors.

Below is an example of a pod spec. The pod has two containers, each requesting 250 millicpu of CPU. The first container requests CPU resources as a fraction (.25), whereas the second requests CPU resources in millicpu (250m).

```
apiVersion: v1
kind: Pod
metadata:
  name: frontend
spec:
  containers:
  - name: app1
    image: images.replex.example/app1:v2
    env:
    resources:
      requests:
        memory: "64Mi"
        cpu: ".25"
      limits:
        memory: "128Mi"
        cpu: ".5"
  - name: app2
    image: images.replex.example/app2:v3
    resources:
      requests:
        memory: "128Mi"
        cpu: "250m"
      limits:
        memory: "256Mi"
        cpu: "500m"
```

**Pod Used CPU** is calculated as the sum of CPU resources consumed by all containers in the pod expressed as a percentage.

![Pod Used CPU](/files/-MFf9PYKLsocbVpp-k4K)

**Pod CPU cost** is calculated as the sum of **Container CPU cost** for all containers in the pod.&#x20;

![Pod CPU cost](/files/-MFf9PYKLsocbVpp-k4K)

**Pod Minimum CPU Usage** is the minimum amount of CPU used by the pod during the selected time range.

**Pod Maximum CPU Usage** is the maximum amount of CPU used by the pod during the selected time range.

**Recommended CPU** is generated by the Replex system and is the recommended CPU requests value for that pod. Recommended CPU is calculated as follows:

```
Recommended CPU = (Average CPU usage + CPU Usage stddev) / % Target CPU Utilization
```

{% hint style="info" %}
Target CPU Utilization in the calculation above is 70%
{% endhint %}

![Pod Min, Max CPU Usage](/files/-MfhPJ5QR_gWRkC_hY_y)

**Standard Deviation** outlined in the CPU column is the stddev in CPU usage for that pod during the selected time range.

![Standard Deviation in CPU Usage](/files/-MfhhI-kJSbHXl8GjM7A)

**Container CPU cost** is the product of **node CPU cost** and the fraction of CPU resources consumed by the container during a specific time interval.&#x20;

```
Container CPU cost = node CPU cost * fraction of container node CPU usage
```

**Node CPU cost** is calculated as the product of **CPU cost per core** and the total number of cores on that node, for a specific time duration.&#x20;

```
node CPU cost = (cpuCoreHourly * cores of node) / 60 * interval duration in minutes 
```

**cpuCoreHourly** (CPU per core per hour) costs are fetched from the cloud providers using Replex’s pricing API.

### RAM

**Pod Requested RAM** is calculated as the sum of memory requests for all containers in the pod.

![Pod Requested RAM](/files/-MFf9PYKLsocbVpp-k4K)

Memory requests are measured in bytes. Each container can request memory resources as a plain integer or as a fixed-point integer with one of these suffixes: E, P, T, G, M, K using `spec.containers[].resources.requests.memory.`

Memory resources can also be requested as power-of-two equivalents: Ei, Pi, Ti, Gi, Mi, Ki.

Below is an example of a pod spec with two containers. The first container has RAM requests of 128Mi whereas the second has RAM requests of 256 Mi.&#x20;

```
apiVersion: v1
kind: Pod
metadata:
  name: frontend
spec:
  containers:
  - name: app1
    image: images.replex.example/app1:v2
    env:
    resources:
      requests:
        memory: "64Mi"
        cpu: ".25"
      limits:
        memory: "128Mi"
        cpu: ".5"
  - name: app2
    image: images.replex.example/app2:v3
    resources:
      requests:
        memory: "128Mi"
        cpu: "250m"
      limits:
        memory: "256Mi"
        cpu: "500m"
```

**Pod Used RAM** is calculated as the sum of memory resources consumed by all containers in the pod expressed as a percentage.

![Pod Used RAM](/files/-MFf9PYKLsocbVpp-k4K)

**Pod RAM cost** is calculated as the sum of **Container RAM cost** for all containers in the pod.&#x20;

![Pod RAM cost](/files/-MFf9PYKLsocbVpp-k4K)

**Pod Minimum RAM Usage** is the minimum amount of RAM used by the pod during the selected time range.

**Pod Maximum RAM Usage** is the maximum amount of RAM used by the pod during the selected time range.

**Recommended RAM** is generated by the Replex system and is the recommended RAM requests value for that pod. Recommended RAM is calculated as follows:

```
Recommended RAM = (Average RAM usage + RAM Usage stddev) / % Target RAM Utilization
```

{% hint style="info" %}
Target RAM Utilization in the calculation above is 70%
{% endhint %}

![Pod Min, Max RAM Usage](/files/-MfhPJ5QR_gWRkC_hY_y)

**Standard Deviation** outlined in the RAM column is the stddev in RAM usage for that pod during the selected time range.

![Standard Deviation in RAM Usage](/files/-Mfhhojt1NUi16dcsIq0)

&#x20;**Container RAM cost** is the product of **node RAM cost** and the fraction of memory resources consumed by the container during a specific time interval.&#x20;

```
Container RAM cost = node RAM cost * fraction of container node RAM usage
```

**Node RAM cost** is the product of **RAM cost per core** and the total number of cores on that node, for a specific time duration.&#x20;

```
node CPU cost = (ramGBHourly  ram of node in GB) / 60 * interval duration in minutes 
```

**ramGBHourly** (RAM per GB per hour) costs are fetched from the cloud providers using Replex’s pricing API.

### **Storage**

**Pod Storage Capacity** is calculated as the size of the Persistent Volume Claim (PVC) that is provisioned for that pod. This number is based on the pod spec.

![Pod Storage Capacity](/files/-MFf9PYKLsocbVpp-k4K)

**Pod Storage cost** is calculated as the cost of PVCs attached to that pod.

![Pod Storage cost](/files/-MFf9PYKLsocbVpp-k4K)

**Total Pod cost** is calculated as the sum of **CPU cost**, **RAM cost** and **Storage cost** for all containers in that pod.

![Pod Total Cost](/files/-MFf9PYKLsocbVpp-k4K)

### Attached Node Disks

**Node Disk Cost** is calculated with the standard GB price of the particular cloud provider. The price is multiplied with the disk capacity and scaled to the required time interval.

```
node disk cost = (standard GB price per hour) / 60 * capacity * interval duration in minutes 
```

**Container Disk Cost** are calculated by distributing the node disk cost equally among all containers running on the node.

```
container disk cost = (node disk cost)/ number of containers running on the node
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.replex.io/concepts/calculations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
