{"id":121,"date":"2023-03-19T08:41:38","date_gmt":"2023-03-19T07:41:38","guid":{"rendered":"http:\/\/10.4.44.99:10084\/?p=121"},"modified":"2023-03-19T08:41:38","modified_gmt":"2023-03-19T07:41:38","slug":"vmware-esxi-snmp-and-esxcli-querys-oid-cpu-memory-memory-used-version-uptime-nic","status":"publish","type":"post","link":"https:\/\/www.winni.at\/wordpress\/?p=121","title":{"rendered":"VMware | ESXi SNMP and esxcli Querys OID (CPU | Memory | Memory USED | Version | Uptime | NIC)"},"content":{"rendered":"\n<p>Here I will show you some ESXi SNMP and esxcli OID querys to get some physical Information of your hosts:<\/p>\n\n\n\n<p>How to install ESXCLI &#8211;&gt;&nbsp;<a href=\"https:\/\/www.winni.at\/index.php\/de\/wissen\/60-install-vmware-vcli-at-redhat-centos-to-check-with-nagios\">Install VMware vCLI at Redhat\/Centos to check with Nagios<\/a><\/p>\n\n\n\n<p><strong>UPTIME<\/strong><\/p>\n\n\n\n<p>Type:&nbsp;ESXCLI<\/p>\n\n\n\n<p>Command:&nbsp;<code>esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' system stats uptime get<\/code><\/p>\n\n\n\n<p>Output:&nbsp;<code>[root@nagios ~]# esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' system stats uptime get&nbsp;<\/code>&nbsp;&#8211;&gt;<strong>&nbsp;3079179765083<\/strong><\/p>\n\n\n\n<p>Output Value:<strong>&nbsp;milliseconds<\/strong><\/p>\n\n\n\n<p><strong>VERSION<\/strong><\/p>\n\n\n\n<p>Type:&nbsp;ESXCLI<\/p>\n\n\n\n<p>Command:&nbsp;<code>esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' system version get<\/code><\/p>\n\n\n\n<p>Output Example:&nbsp;<code>[root@nagios ~]# esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' system version get&nbsp;<\/code>&nbsp;&#8211;&gt;<strong>&nbsp;<\/strong><\/p>\n\n\n\n<p><strong>Product: VMware ESXi<\/strong><\/p>\n\n\n\n<p><strong>Version: 5.5.0<\/strong><\/p>\n\n\n\n<p><strong>Build: Releasebuild-2403361<\/strong><\/p>\n\n\n\n<p><strong>Update: 2<\/strong><\/p>\n\n\n\n<p>Output Value:<strong>&nbsp;Product, Version, Buildnumber and Update<\/strong><\/p>\n\n\n\n<p><strong>CPU LOAD<\/strong><\/p>\n\n\n\n<p>Type:&nbsp;ESXCLI<\/p>\n\n\n\n<p>Command:&nbsp;<code>esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' system process stats load get<\/code><\/p>\n\n\n\n<p>Output Example:&nbsp;<code>[root@nagios ~]# esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' system process stats load get&nbsp;<\/code>&#8211;&gt;<strong>&nbsp;<\/strong><\/p>\n\n\n\n<p><strong>Load1Minute: 0.22<\/strong><\/p>\n\n\n\n<p><strong>Load15Minutes: 0.17<\/strong><\/p>\n\n\n\n<p><strong>Load5Minutes: 0.19<\/strong><\/p>\n\n\n\n<p>Output Value:<strong>&nbsp;CPU Load Average within 1, 5 and 15 Minutes<\/strong><\/p>\n\n\n\n<p><strong>MEMORY<\/strong><\/p>\n\n\n\n<p>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!<\/p>\n\n\n\n<p>TOTAL MEMORY<\/p>\n\n\n\n<p>Type:&nbsp;ESXCLI<\/p>\n\n\n\n<p>Command:&nbsp;<code>esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' hardware memory get<\/code><\/p>\n\n\n\n<p>Output Example:&nbsp;<code>[root@nagios ~]# esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' hardware memory get&nbsp;<\/code>&#8211;&gt;<strong>&nbsp;<\/strong><\/p>\n\n\n\n<p><strong>Physical Memory: 549719330816 Bytes<\/strong><\/p>\n\n\n\n<p><strong>Reliable Memory: 0 Bytes<\/strong><\/p>\n\n\n\n<p><strong>NUMA Node Count: 2<\/strong><\/p>\n\n\n\n<p>Output Value:<strong>&nbsp;Total installed Memory in Bytes<\/strong><\/p>\n\n\n\n<p>USED&nbsp;MEMORY<\/p>\n\n\n\n<p>This is a little bit more difficult because there is no esxcli command or snmpwalk to get a single value of used memory.<\/p>\n\n\n\n<p>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 &#8211;&gt;&nbsp;<a href=\"https:\/\/www.winni.at\/index.php\/de\/wissen\/80-vmware-esxi-host-snmp-access-v2c\">VMware ESXi Host SNMP Access v2c<\/a><\/p>\n\n\n\n<p>Type:&nbsp;SNMP<\/p>\n\n\n\n<p>Command:&nbsp;<code>snmpwalk -v2c -c COMMUNITY HOSTNAME 1.3.6.1.2.1.25.5.1.1.2<\/code><\/p>\n\n\n\n<p>Output Example:&nbsp;<code>snmpwalk -v2c -c COMMUNITY HOSTNAME 1.3.6.1.2.1.25.5.1.1.2&nbsp;<\/code>&nbsp;&#8211;&gt;<strong>&nbsp;<\/strong><\/p>\n\n\n\n<p>HOST-RESOURCES-MIB::hrSWRunPerfMem.33140 = INTEGER: 2296 KBytes<\/p>\n\n\n\n<p>HOST-RESOURCES-MIB::hrSWRunPerfMem.33378 = INTEGER: 5808 KBytes<\/p>\n\n\n\n<p>HOST-RESOURCES-MIB::hrSWRunPerfMem.33379 = INTEGER: 8400 KBytes<\/p>\n\n\n\n<p>HOST-RESOURCES-MIB::hrSWRunPerfMem.33388 = INTEGER: 764 KBytes<\/p>\n\n\n\n<p>HOST-RESOURCES-MIB::hrSWRunPerfMem.33411 = INTEGER: 13516 KBytes<\/p>\n\n\n\n<p>HOST-RESOURCES-MIB::hrSWRunPerfMem.33430 = INTEGER: 764 KBytes<\/p>\n\n\n\n<p>HOST-RESOURCES-MIB::hrSWRunPerfMem.33452 = INTEGER: 6736 KBytes<\/p>\n\n\n\n<p>HOST-RESOURCES-MIB::hrSWRunPerfMem.33465 = INTEGER: 776 KBytes<\/p>\n\n\n\n<p>HOST-RESOURCES-MIB::hrSWRunPerfMem.33514 = INTEGER: 5540 KBytes<\/p>\n\n\n\n<p>HOST-RESOURCES-MIB::hrSWRunPerfMem.33588 = INTEGER: 764 KBytes<\/p>\n\n\n\n<p>HOST-RESOURCES-MIB::hrSWRunPerfMem.33611 = INTEGER: 2760 KBytes<\/p>\n\n\n\n<p>&#8230;..<\/p>\n\n\n\n<p>This OID Subtree has a LOT of Values. In my case about 94 single Values!! But&nbsp;<strong>THERE<\/strong>&nbsp;ESXi stores their memory usage!&nbsp;<\/p>\n\n\n\n<p>You only had to summarize the whole values and you will get the memory usage.<\/p>\n\n\n\n<p>I have done this in some simple php scripts:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Auslesen des Gesamten Arbeitsspeichers\n\n$ausgabeMEMHOSTall = shell_exec(\"esxcli --username \".$username.\" --password '\".$password.\"' --server \".$host.\" hardware memory get\");\n\npreg_match_all(\"\/&#91;\\d\\.]+\/\", \"$ausgabeMEMHOSTall\", $ergebnisMEMHOSTallbytetmp);\n\n$ergebnisMEMHOSTallbyte = $ergebnisMEMHOSTallbytetmp&#91;0]&#91;0];\n\n \n\n\/\/Auslesen des verwendeten Speichers\n\n$ausgabeMEMHOSTusedkb = shell_exec(\"snmpwalk -v2c -c public \".$host.\" 1.3.6.1.2.1.25.5.1.1.2\");\n\n \n\n\/\/Wir suchen uns nur die Werte raus - diese stehen im Normalfall wie folgt drin: : 764 KBytes\n\npreg_match_all(\"\/: (&#91;\\d]+)\/\", $ausgabeMEMHOSTusedkb, $treffer);\n\n \n\n\/\/Wir zaehlen zusammen\n\n$result = 0;\n\nforeach($treffer&#91;0] as $kb_used)\n\n{\n\n\/\/Wir filter noch den Doppelpunkt weg\n\n$kb_used = str_replace(\": \",\"\", $kb_used);\n\n$result = $result + intval($kb_used);\n\n}\n<\/code><\/pre>\n\n\n\n<p>Within the&nbsp;<strong>$result<\/strong>&nbsp;variable you will have the used memory of your ESXi host in KB.&nbsp;<\/p>\n\n\n\n<p>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<\/p>\n\n\n\n<p>Output Value:<strong>&nbsp;Used Memory in a lot of values. Summarize them and you get the used memory size.<\/strong><\/p>\n\n\n\n<p><strong>NIC<\/strong><\/p>\n\n\n\n<p>Type:&nbsp;ESXCLI<\/p>\n\n\n\n<p>Command:&nbsp;<code>esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' network nic list<\/code><\/p>\n\n\n\n<p>Output Example:&nbsp;<code>[root@nagios ~]# esxcli --server HOSTNAME --username USERNAME --password 'PASSWORD' network nic list&nbsp;<\/code>&#8211;&gt;<\/p>\n\n\n\n<p><strong>Name &nbsp; &nbsp;PCI Device &nbsp; &nbsp; Driver &nbsp;Link &nbsp;Speed &nbsp;Duplex &nbsp;MAC Address &nbsp; &nbsp; &nbsp; &nbsp; MTU &nbsp;Description<\/strong><\/p>\n\n\n\n<p><strong>&#8212;&#8212; &nbsp;&#8212;&#8212;&#8212;&#8212;- &nbsp;&#8212;&#8212; &nbsp;&#8212;- &nbsp;&#8212;&#8211; &nbsp;&#8212;&#8212; &nbsp;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &nbsp;&#8212;- &nbsp;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/strong><\/p>\n\n\n\n<p><strong>vmnic0 &nbsp;0000:003:00.0 &nbsp;tg3 &nbsp; &nbsp; Up &nbsp; &nbsp; 1000 &nbsp;Full &nbsp; &nbsp;ac:16:2d:6e:86:90 &nbsp;1500 &nbsp;Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet<\/strong><\/p>\n\n\n\n<p><strong>vmnic1 &nbsp;0000:003:00.1 &nbsp;tg3 &nbsp; &nbsp; Up &nbsp; &nbsp; 1000 &nbsp;Full &nbsp; &nbsp;ac:16:2d:6e:86:91 &nbsp;1500 &nbsp;Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet<\/strong><\/p>\n\n\n\n<p><strong>vmnic2 &nbsp;0000:003:00.2 &nbsp;tg3 &nbsp; &nbsp; Up &nbsp; &nbsp; 1000 &nbsp;Full &nbsp; &nbsp;ac:16:2d:6e:86:92 &nbsp;1500 &nbsp;Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet<\/strong><\/p>\n\n\n\n<p><strong>vmnic3 &nbsp;0000:003:00.3 &nbsp;tg3 &nbsp; &nbsp; Up &nbsp; &nbsp; 1000 &nbsp;Full &nbsp; &nbsp;ac:16:2d:6e:86:93 &nbsp;1500 &nbsp;Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet<\/strong><\/p>\n\n\n\n<p><strong>vmnic4 &nbsp;0000:024:00.0 &nbsp;tg3 &nbsp; &nbsp; Up &nbsp; &nbsp; 1000 &nbsp;Full &nbsp; &nbsp;2c:76:8a:57:83:88 &nbsp;1500 &nbsp;Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet<\/strong><\/p>\n\n\n\n<p><strong>vmnic5 &nbsp;0000:024:00.1 &nbsp;tg3 &nbsp; &nbsp; Up &nbsp; &nbsp; 1000 &nbsp;Full &nbsp; &nbsp;2c:76:8a:57:83:89 &nbsp;1500 &nbsp;Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet<\/strong><\/p>\n\n\n\n<p><strong>vmnic6 &nbsp;0000:024:00.2 &nbsp;tg3 &nbsp; &nbsp; Up &nbsp; &nbsp; 1000 &nbsp;Full &nbsp; &nbsp;2c:76:8a:57:83:8a &nbsp;1500 &nbsp;Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet<\/strong><\/p>\n\n\n\n<p><strong>vmnic7 &nbsp;0000:024:00.3 &nbsp;tg3 &nbsp; &nbsp; Up &nbsp; &nbsp; 1000 &nbsp;Full &nbsp; &nbsp;2c:76:8a:57:83:8b &nbsp;1500 &nbsp;Broadcom Corporation NetXtreme BCM5719 Gigabit Ethernet<\/strong><\/p>\n\n\n\n<p>Output Value:<strong>&nbsp;All NICs and their state<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here I will show you some ESXi SNMP and esxcli OID querys to get some physical Information of your hosts:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[3],"tags":[68,182,184,185,186,187,189,191,193],"class_list":["post-121","post","type-post","status-publish","format-standard","hentry","category-kb","tag-esxi-oid","tag-vmware","tag-vmware-cpu","tag-vmware-esxi","tag-vmware-esxi-oid","tag-vmware-esxi-oid-query","tag-vmware-memory","tag-vmware-oid","tag-vmware-version"],"_links":{"self":[{"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=121"}],"version-history":[{"count":0,"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/121\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.winni.at\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}