0 Replies Latest reply on Dec 5, 2018 2:43 PM by maximumcookie

    How to query for VM stats?

    maximumcookie Lurker

      Hey guys,

       

      I'm attempting to query for VM stats, but I'm running into an error that I don't fully understand.  What I did was grab the Vmware.Vim dll from the PowerCLI install and have been using that.  Below is the relevant code.

       

       

      VimClient vimClient = new VMware.Vim.VimClientImpl();

      var serviceContent = vimClient.Connect(hostname, VMware.Vim.CommunicationProtocol.Https, null);

      var userSession = vimClient.Login(un, pwd);

       

      String[] viewProperties = null;

       

      NameValueCollection filter = new NameValueCollection();

      filter.Add("Name", vmName2LookFor);

       

       

      var ret = vimClient.FindEntityViews(typeof(VMware.Vim.VirtualMachine), null, filter, viewProperties);

      var VMs = ret.Cast<VMware.Vim.VirtualMachine>().ToList();

       

       

      var vm = VMs.FirstOrDefault();

      var pm = new VMware.Vim.PerformanceManager(vimClient, vm.MoRef);

       

       

      //pm.QueryPerf()

      var summary = pm.QueryAvailablePerfMetric(vm.MoRef, DateTime.Now.AddDays(-1), DateTime.Now, null);

       

       

      The above QueryAvailablePerfMetric is failing with the following error:

       

      VMware.Vim.VimException: 'The request refers to an unexpected or unknown type.'

       

       

      I'm unsure exacty what this exception means, but I'm guessing it doesn't like the MoRef I sent in?  I can pull stats off this same VM using the PowerCLI Get-Stat and Get-StatType cmdlets.

       

      Can someone help me out?  What am I missing here?