* You should have received a copy of the GNU General Public License * along with PHP-ESX. If not, see <http://www.gnu.org/licenses/>. * */ if (count($_SERVER['argv']) != 6) { echo 'Usage: php ' . $_SERVER['argv'][0] . ' <host> <username> <password> <vmname> <nic #> vmname the name of the virtual machine nic # which network interface to query (starting at 1) '; exit; } require_once dirname(__FILE__) . '/../../class_esx.php'; try { $esx = new esx(); $esx->connect($_SERVER['argv'][1], $_SERVER['argv'][2], $_SERVER['argv'][3]); $vm = $esx->find_entity_view('VirtualMachine', null, array('config.name' => $_SERVER['argv'][4])); $stats = $esx->get_stats($vm); $metrics = array(); foreach ($stats as $stat) { if ($stat->groupInfo->key == 'net' && $stat->instance == $_SERVER['argv'][5] + 3999) { $metrics[$stat->nameInfo->key] = $stat->value; } } if (isset($metrics['bytesTx']) && isset($metrics['bytesRx']) && isset($metrics['droppedTx']) && isset($metrics['droppedRx'])) { echo 'bytestx:' . $metrics['bytesTx'] . ' bytesrx:' . $metrics['bytesRx'] . ' droppedtx:' . $metrics['droppedTx'] . ' droppedrx:' . $metrics['droppedRx'] . "\n"; } else { die('Unknown NIC #' . $_SERVER['argv'][5] . "\n"); } $esx->disconnect(); } catch (Exception $e) { die($e->getMessage() . "\n");