如何通过 pyvmomi 或 cli 确定 ESX 虚拟机管理程序上的总内存、空闲内存、可用内存?

Sha*_*rad 2 python esx esxi pyvmomi

我正在寻找 ESX/ESXi 特定命令/示例 pyvmomi API 来确定虚拟机管理程序上的系统内存信息 - 可用/总/已使用。

小智 6

运行 ESXi 主机命令

vsish -e get /memory/comprehensive
Run Code Online (Sandbox Code Playgroud)

原始输出

Comprehensive {
   Physical memory estimate:12454784 KB
   Given to VMKernel:12454784 KB
   Reliable memory:0 KB
   Discarded by VMKernel:1580 KB
   Mmap critical space:0 KB
   Mmap buddy overhead:3084 KB
   Kernel code region:18432 KB
   Kernel data and heap:14336 KB
   Other kernel:1421360 KB
   Non-kernel:120036 KB
   Reserved memory at low addresses:59900 KB
   Free:10875956 KB
}
Run Code Online (Sandbox Code Playgroud)

格式

vsish -e get /memory/comprehensive | sed 's/:/ /' | awk '
    /Phys/ { phys = $(NF-1); units = $NF; width = length(phys) }
    /Free/ { free = $(NF-1) }
    END    { print width, units, phys, phys-free, free }' |
    while read width units phys used free; do
        printf "Phys %*d %s\n" $width $phys $units
        printf "Used %*d %s\n" $width $used $units
        printf "Free %*d %s\n" $width $free $units
    done
Run Code Online (Sandbox Code Playgroud)

输出

Phys 12454784 KB
Used  1580564 KB
Free 10874220 KB
Run Code Online (Sandbox Code Playgroud)