我正在寻找特定于ESX / ESXi的命令/示例pyvmomi API来确定虚拟机管理程序上的系统内存信息 - 免费/总计/已使用。
答案 0 :(得分:3)
运行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 %s\n" $width $phys $units
printf "Used %*d %s\n" $width $used $units
printf "Free %*d %s\n" $width $free $units
done
输出
Phys 12454784 KB
Used 1580564 KB
Free 10874220 KB
答案 1 :(得分:1)
由于问题标题中还提到了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机器上。
在Linux终端的包含perf.csv的文件夹中运行以下脚本:
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服务器发布。
答案 2 :(得分:0)
我找到了答案:
https://gist.github.com/deviantony/5eff8d5c216c954973e2
具体来说,这些行:
memoryCapacity = hardware.memorySize
memoryCapacityInMB = hardware.memorySize/MBFACTOR
memoryUsage = stats.overallMemoryUsage
freeMemoryPercentage = 100 - (
(float(memoryUsage) / memoryCapacityInMB) * 100
)