VMware | ESXi SNMP and esxcli Querys OID (CPU | Memory | Memory USED | Version | Uptime | NIC)
Here I will show you some ESXi SNMP and esxcli OID querys to get some physical Information of your hosts:
How to install ESXCLI –> Install VMware vCLI at Redhat/Centos to check with Nagios
UPTIME
Type: ESXCLI
Command: esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' system stats uptime get
Output: [root@nagios ~]# esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' system stats uptime get
–> 3079179765083
Output Value: milliseconds
VERSION
Type: ESXCLI
Command: esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' system version get
Output Example: [root@nagios ~]# esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' system version get
–>
Product: VMware ESXi
Version: 5.5.0
Build: Releasebuild-2403361
Update: 2
Output Value: Product, Version, Buildnumber and Update
CPU LOAD
Type: ESXCLI
Command: esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' system process stats load get
Output Example: [root@nagios ~]# esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' system process stats load get
–>
Load1Minute: 0.22
Load15Minutes: 0.17
Load5Minutes: 0.19
Output Value: CPU Load Average within 1, 5 and 15 Minutes
MEMORY
The Memory Querys are a little bit more difficult because you will get only a simple Value on the total of installed memory but no simple value of used memory. But there is a hint!
TOTAL MEMORY
Type: ESXCLI
Command: esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' hardware memory get
Output Example: [root@nagios ~]# esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' hardware memory get
–>
Physical Memory: 549719330816 Bytes
Reliable Memory: 0 Bytes
NUMA Node Count: 2
Output Value: Total installed Memory in Bytes
USED MEMORY
This is a little bit more difficult because there is no esxcli command or snmpwalk to get a single value of used memory.
But a ESXi Host does have the used memory values to query. Not a single on but a couple of them!! Therefore you need SNMP Access to your ESXi Host –> VMware ESXi Host SNMP Access v2c
Type: SNMP
Command: snmpwalk -v2c -c COMMUNITY HOSTNAME 1.3.6.1.2.1.25.5.1.1.2
Output Example: snmpwalk -v2c -c COMMUNITY HOSTNAME 1.3.6.1.2.1.25.5.1.1.2
–>
HOST-RESOURCES-MIB::hrSWRunPerfMem.33140 = INTEGER: 2296 KBytes
HOST-RESOURCES-MIB::hrSWRunPerfMem.33378 = INTEGER: 5808 KBytes
HOST-RESOURCES-MIB::hrSWRunPerfMem.33379 = INTEGER: 8400 KBytes
HOST-RESOURCES-MIB::hrSWRunPerfMem.33388 = INTEGER: 764 KBytes
HOST-RESOURCES-MIB::hrSWRunPerfMem.33411 = INTEGER: 13516 KBytes
HOST-RESOURCES-MIB::hrSWRunPerfMem.33430 = INTEGER: 764 KBytes
HOST-RESOURCES-MIB::hrSWRunPerfMem.33452 = INTEGER: 6736 KBytes
HOST-RESOURCES-MIB::hrSWRunPerfMem.33465 = INTEGER: 776 KBytes
HOST-RESOURCES-MIB::hrSWRunPerfMem.33514 = INTEGER: 5540 KBytes
HOST-RESOURCES-MIB::hrSWRunPerfMem.33588 = INTEGER: 764 KBytes
HOST-RESOURCES-MIB::hrSWRunPerfMem.33611 = INTEGER: 2760 KBytes
…..
This OID Subtree has a LOT of Values. In my case about 94 single Values!! But THERE ESXi stores their memory usage!
You only had to summarize the whole values and you will get the memory usage.
I have done this in some simple php scripts:
//Auslesen des Gesamten Arbeitsspeichers
$ausgabeMEMHOSTall = shell_exec("esxcli --username ".$username." --password '".$password."' --server ".$host." hardware memory get");
preg_match_all("/[\d\.]+/", "$ausgabeMEMHOSTall", $ergebnisMEMHOSTallbytetmp);
$ergebnisMEMHOSTallbyte = $ergebnisMEMHOSTallbytetmp[0][0];
//Auslesen des verwendeten Speichers
$ausgabeMEMHOSTusedkb = shell_exec("snmpwalk -v2c -c public ".$host." 1.3.6.1.2.1.25.5.1.1.2");
//Wir suchen uns nur die Werte raus - diese stehen im Normalfall wie folgt drin: : 764 KBytes
preg_match_all("/: ([\d]+)/", $ausgabeMEMHOSTusedkb, $treffer);
//Wir zaehlen zusammen
$result = 0;
foreach($treffer[0] as $kb_used)
{
//Wir filter noch den Doppelpunkt weg
$kb_used = str_replace(": ","", $kb_used);
$result = $result + intval($kb_used);
}
Within the $result variable you will have the used memory of your ESXi host in KB.
Now you have just to convert them in KB/MB/GB/.. and you have a relative proper value of the used memory of your esxi host
Output Value: Used Memory in a lot of values. Summarize them and you get the used memory size.
NIC
Type: ESXCLI
Command: esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' network nic list
Output Example: [root@nagios ~]# esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' network nic list
–>
Name PCI Device Driver Link Speed Duplex MAC Address MTU Description
—— ————- —— —- —– —— —————– —- ——————————————————-
vmnic0 0000:003:00.0 tg3 Up 1000 Full ac:16:2d:6e:86:90 1500 Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet
vmnic1 0000:003:00.1 tg3 Up 1000 Full ac:16:2d:6e:86:91 1500 Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet
vmnic2 0000:003:00.2 tg3 Up 1000 Full ac:16:2d:6e:86:92 1500 Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet
vmnic3 0000:003:00.3 tg3 Up 1000 Full ac:16:2d:6e:86:93 1500 Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet
vmnic4 0000:024:00.0 tg3 Up 1000 Full 2c:76:8a:57:83:88 1500 Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet
vmnic5 0000:024:00.1 tg3 Up 1000 Full 2c:76:8a:57:83:89 1500 Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet
vmnic6 0000:024:00.2 tg3 Up 1000 Full 2c:76:8a:57:83:8a 1500 Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet
vmnic7 0000:024:00.3 tg3 Up 1000 Full 2c:76:8a:57:83:8b 1500 Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet
Output Value: All NICs and their state