How Does the Kubernetes Agent Calculate Node CPU and Memory Utilization?

How does the Kubernetes agent calculate node CPU and memory utilization?

The Kubernetes agent calculates node CPU and memory utilization based on the total resource capacity and the allocatable resources available for workloads. This article explains how these utilization percentages are calculated and helps you understand the difference between capacity-based and allocatable resource utilization.

Memory utilization

The memory utilization is calculated using the node's memory working set relative to its total memory capacity or allocatable memory.

Memory utilization as a percentage of capacity
This formula calculates the percentage of the total physical memory capacity used by the node:
Memory utilization (% of capacity) = (Memory working set / RAM capacity) x 100
Memory utilization as a percentage of allocatable memory
This formula calculates the percentage of memory used out of the memory allocated for workloads on the node:                 
Memory utilization (% of allocatable memory) = (Memory working set / Allocatable RAM) x 100                                                 
Example
Consider a node with a capacity of 16GiB, 14GiB of allocatable memory, and a working set of 4GiB.
  1. Memory utilization (% of capacity) = (4 /16) x 100 = 25%
  2. Memory utilization (% of allocatable memory) = (4/14) x 100 = 28.57%

CPU utilization

The CPU utilization is calculated by comparing the node's CPU usage in millicores against its total CPU capacity or allocatable CPU resources.

CPU utilization as a percentage of capacity
This formula measures the percentage of the node's total CPU capacity that's being used:
                                                                                   CPU usage (millicores)
CPU utilization (% of capacity) = ------------------------------------------------------------ x 100
                                                                                 CPU capacity (cores) x 1,000
CPU utilization as a percentage of allocatable CPU
This formula measures the CPU usage as a percentage of the CPU resources that are allocatable to workloads on the node:
                                                                                                     CPU usage (millicores)
CPU utilization (% of allocatable CPU) = ------------------------------------------------------------- x 100
                                                                                                 Allocatable CPU (cores) x 1,000
Example
Assume a node has a capacity of eight cores, has seven allocatable cores, and uses 2,000 millicores:
  1. CPU utilization (% of capacity) = (2,000/8,000) x 100 = 25%
  2. CPU utilization (% of allocatable CPU) = (2,000/7,000) x 100 = 28.57%

Related article

  1. How is the total memory utilization calculated for a Linux server monitor?
  2. How is the total CPU usage calculated for a Linux server monitor?