我正在寻找ESX/ESXI特定命令/样本Pyvmomi API,以确定Hyprovisor上的系统内存信息 - 免费/total/persed/persed。
运行ESXI主机命令
vsish -e get /memory/comprehensive
原始输出
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
}
格式
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 %sn" $width $phys $units
printf "Used %*d %sn" $width $used $units
printf "Free %*d %sn" $width $free $units
done
输出
Phys 12454784 KB
Used 1580564 KB
Free 10874220 KB
当问题标题中提到的CLI时,我将添加如何通过ESXI的命令行检索内存使用情况。我使用了ESXI 6.7,但是由于版本ESX 4.0,这应该有效,因为仅在ESXI主机上运行性能。
-
在ESXI SSH会话中运行以收集性能数据:
# Source: https://kb.vmware.com/s/article/1004953 esxtop -b -n 1 > /tmp/perf.csv
-
SCP将性能数据与Linux计算机。
-
在包含perf.csv的文件夹中的Linux终端中运行下面的脚本:
printf "Total Memory: "; line_overall_mem="$(head -1 perf.csv | tr "," "12" | grep -in "Machine MBytes" | cut -d ":" -f1)"; tail -1 perf.csv | tr "," "12" | sed -n "${line_overall_mem}p" | sed 's/"//g'; printf "Free Memory: "; line_free_mem="$(head -1 perf.csv | tr "," "12" | grep -in 'Memory\Free MBytes' | cut -d ":" -f1)"; tail -1 perf.csv | tr "," "12" | sed -n "${line_free_mem}p" | sed 's/"//g'
-
输出应该是:
Total Memory: 24566 Free Memory: 7519
我有6.7 U2的夫妇免费运行ESXI。VMware的硬件兼容性列表实际上指出,我的硬件仅与ESXI 4.1兼容,但它们仍处于运行良好。
我每天都有上述信息自动写给NFS共享一次。从NFS共享信息通过Linux VM Web服务器发布。
我找到了答案:
https://gist.github.com/deviantony/5eff8d5c216c954973e2
特别是这些行:
memoryCapacity = hardware.memorySize
memoryCapacityInMB = hardware.memorySize/MBFACTOR
memoryUsage = stats.overallMemoryUsage
freeMemoryPercentage = 100 - (
(float(memoryUsage) / memoryCapacityInMB) * 100
)