Get network usage from vmware.vim.vimclient


Fred

I'm using the underlying PowerCLI dll to get some C# functionality, but I can't seem to find documentation on how to get the statistics.

This is the PowerCLI I'm trying to recreate in C#.

$vm | Get-Stat -stat 'net.usage.average'

I can log in via the VMware.Vim.VimClientImpl#connect method and I can get the virtual machine via the VMware.Vim.VimClient#FindEntityViews method, but from there I don't know how to get the network usage information and I can't find documentation about it via Google .

If there is documentation for these APIs, I'd love to have them, but in the meantime, does anyone know how to get this information?

Fred

I figured it out by staring at the SOAP request and making some intuitive leaps.

I believe, the VMWare API is state-based, similar to how the X11 API is state-based (you can deal with various objects in server memory).

Specifically, you first connect a session to the server, then use that session to log in. When you connect to a session, vmware will return a list of "manager objects" and their subsequent MoRefs. Therefore, the correct way to query this information is as follows:

VimClient vimClient = new VMware.Vim.VimClientImpl();
var serviceContent = vimClient.Connect(hostname, VMware.Vim.CommunicationProtocol.Https, null);
var userSession = vimClient.Login(un, pwd);

NameValueCollection filter = new NameValueCollection();
filter.Add("Name", vmName2LookFor);

String[] viewProperties = null;

var VMs = vimClient.FindEntityViews(typeof(VMware.Vim.VirtualMachine), null, filter, viewProperties);
              .Cast<VMware.Vim.VirtualMachine>()
              .ToList();
var vm = VMs.FirstOrDefault(); // blindly grab for example purposes

var pm = new VMware.Vim.PerformanceManager(vimClient, serviceContent.PerfManager);
pm.QueryAvailablePerfMetric(vm.MoRef, DateTime.Now.AddDays(-1), DateTime.Now, null)

Note that when creating the PerformanceManager object, we'll get the MoRef from the ServiceContent object that was created when initially connecting to the VMWare API .

I believe it's possible to version control the internal manager this way, but that's just a guess.

Also note that I used vimClient.FindEntityViews for illustration purposes, I could have used a single vimClient.FindEntityView as well.

Third note: MoRef stands for "Managed Object Reference".

Fourth note: For performance reasons, viewProperties in vimClient.FindEntityViews informs vmware to send only the specified properties. For example, finding a VM by IP involves getting all the VMs, and searching through them all to find the VM with the IP you're looking for. You don't need to care about any other properties, so you can tell vmware not to send them. If you have a lot of infrastructure then this will greatly improve performance. In the above case, if I am interested in IP addresses, I would

String[] viewProperties = new[]{ "Guest.Net" };

Related


Get network usage from vmware.vim.vimclient

Fred I'm using the underlying PowerCLI dll to get some C# functionality, but I can't seem to find documentation on how to get the statistics. This is the PowerCLI I'm trying to recreate in C#. $vm | Get-Stat -stat 'net.usage.average' I can log in via the VMwa

VBA get network usage from network interface

hardly I'm having trouble getting ethernet usage from task manager. I have CPU and RAM memory usage, but I can't use ethernet right now. I'll be happy if someone helps me, thanks. My code so far: Private Type MEMORYSTATUS dwLength As Long dwMemoryL

Get network usage on terminal from specific date

ice Tianyuan network usage in the month, day, hour or previous 10 years I can get . Is there anyway I can get the network usage from a specific date on the terminal? Via vnstat or other tools?vnstat edit: I want usage from a specific date to the current date o

From VMWare to VirtualBox - no network

username I used ovftool to convert a VMWare Windows Server 2003 image to OVF. Then I imported it into VirtualBox - works fine, except there is no network connection. I tried NAT, bridged adapter and host only. But in all 3 cases I don't have any network connec

From VMWare to VirtualBox - no network

username I used ovftool to convert a VMWare Windows Server 2003 image to OVF. Then I imported it into VirtualBox - works fine, except there is no network connection. I tried NAT, bridged adapter and host only. But in all 3 cases I don't have any network connec

Calculate network usage from server

term cap I am trying to calculate the network utilization % of a server in any snmp traffic (input or output) in the network. I have followed the steps below, can anyone point out where I am going wrong in this process? Step 1: Run tcpdump for a minute to capt

Calculate network usage from server

term cap I am trying to calculate the network utilization % of a server in any snmp traffic (input or output) in the network. I have followed the steps below, can anyone point out where I am going wrong in this process? Step 1: Run tcpdump for a minute to capt

network win 8 from vmware - parent osx

q I am running vmware 5.0.1 on OSX 10.8.5 and Windows 8 machine. I can't seem to network my Windows 8 computer with other Windows computers. However, I can connect to the internet. I'm only running 1 virtual machine, the other Windows laptops I'm trying to con

withSession and memory usage from Network.Wreq

or I'm using the Network.Wreqbenchmark and it's working fine, but I'd reduce the memory usage simulated per session (if possible). My minimal example just compares the spawning process (and doing some trivial IO) with the spawning withSessioncontext (where my

withSession and memory usage from Network.Wreq

or I'm using the Network.Wreqbenchmark and it's working fine, but I would reduce the memory usage per session simulation (if possible). My minimal example just compares the spawning process (and doing some trivial IO) to the spawning withSessioncontext (where

withSession and memory usage from Network.Wreq

Kyushu I'm using the Network.Wreqbenchmark and it's working fine, but I'd reduce the memory usage simulated per session (if possible). My minimal example compares just generating the process (and doing some trivial IO) vs. generating the create withSessioncont

Find out network usage from your router

Christian Katsarov I have a simple TP-LINK TL-WR841ND router and would like to ask how I can find out the local network usage. I see received/sent packets in the wireless stats, but not sure what exactly that means. Any help would be greatly appreciated. Thank

withSession and memory usage from Network.Wreq

Kyushu I'm using the Network.Wreqbenchmark and it's working fine, but I'd reduce the memory usage simulated per session (if possible). My minimal example compares just generating the process (and doing some trivial IO) vs. generating the create withSessioncont

Find out network usage from your router

Christian Katsarov I have a simple TP-LINK TL-WR841ND router and would like to ask how I can find out the local network usage. I see received/sent packets in the wireless stats, but not sure what exactly that means. Any help would be greatly appreciated. Thank

No network access with Ubuntu on Vmware

ninja 2k I am trying to get an Ubuntu virtual machine to connect to my network. I've set up a static IP address, but I can't get any communication with the network. I have installed VMWare Tools. The network card is set to bridged networking. I am running Ubun

Get flags from network interface

pnovotnak : Looking at the net/interface.go code, it seems that the only way to get the interface flags is a string. This is real? if strings.Contains(i.Flags.String(), "broadcast") { Feel creepy. Tim Cooper: net.Interface.Flagsis a bitmask. To see if an inte

Get flags from network interface

pnovotnak : Looking at the net/interface.go code, it seems that the only way to get the interface flags is a string. This is real? if strings.Contains(i.Flags.String(), "broadcast") { Feel creepy. Tim Cooper: net.Interface.Flagsis a bitmask. To see if an inte

Get flags from network interface

pnovotnak : Looking at the net/interface.go code, it seems that the only way to get the interface flags is a string. This is real? if strings.Contains(i.Flags.String(), "broadcast") { Feel creepy. Tim Cooper: net.Interface.Flagsis a bitmask. To see if an inte

Get flags from network interface

pnovotnak : Looking at the net/interface.go code, it seems that the only way to get the interface flags is a string. This is real? if strings.Contains(i.Flags.String(), "broadcast") { Feel creepy. Tim Cooper: net.Interface.Flagsis a bitmask. To see if an inte

Get flags from network interface

Punovotnak Looking at the net/interface.go code, it seems that the only way to get the interface flags is a string. This is real? if strings.Contains(i.Flags.String(), "broadcast") { Feel creepy. Tim Cooper net.Interface.Flagsis a bitmask. To see if an interf

Tkinter get directory from network

DGMS89 Scenario: I'm trying to get some file paths to use my code further. For this, I use tkinter and the askdirectory function to allow the user to make folder selections. The code below usually finds the folder in my computer, but in this case I want to acc

Get image from network with authentication

lucgian841 In my iOS app I need to load an image from the web, but the image is on a server where username and password must be provided. I try to use this code: - (void) loadImageFromWeb:(NSString *)urlImg { NSURL* url = [NSURL URLWithString:urlImg];

Get flags from network interface

pnovotnak : Looking at the net/interface.go code, it seems that the only way to get the interface flags is a string. This is real? if strings.Contains(i.Flags.String(), "broadcast") { Feel creepy. Tim Cooper: net.Interface.Flagsis a bitmask. To see if an inte