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

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

Costs previous 30 days

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

Total cost

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.

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

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

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.

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.

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

Savings

Cluster Savings represent the cost savings that can be made by optimising cluster resource utilization.

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%

Utilized cost

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.

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.

Cluster score

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.

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.

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

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

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.

CPU

Pod Requested CPU is calculated as the sum of CPU requests for all containers in the pod.

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 CPU cost is calculated as the sum of Container CPU cost for all containers in the pod.

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

Target CPU Utilization in the calculation above is 70%

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

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.

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.

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.

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.

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 RAM cost is calculated as the sum of Container RAM cost for all containers in the pod.

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

Target RAM Utilization in the calculation above is 70%

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

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.

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.

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 cost is calculated as the cost of PVCs attached to that pod.

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

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

Last updated