VMware {code} Community
sajuptpm
Contributor
Contributor

ERROR: 'A specified parameter was not correct. metricId' while executing QueryPerfComposite

ERROR: 'A specified parameter was not correct. metricId' while executing QueryPerfComposite.

Note:
* Same code is working (but not returing metric of holding entities) if i replace perfMetric_cpu.instance = "*" with perfMetric_cpu.instance = ""


client = Client("192.168.0.109", "root", "vmware1") ##vCenter
host = HostSystem.get(client, name="192.168.0.134")

def get_metrics_QueryPerfComposite(client, mob):
    statInterval = client.sc.perfManager.QueryPerfProviderSummary(entity=mob)

    perfMetric_cpu = client.create("PerfMetricId")
    perfMetric_cpu.counterId = get_perf_counter(client)
    perfMetric_cpu.instance = "*"

    perfSpec = client.create("PerfQuerySpec")
    perfSpec.entity = mob._mo_ref
    perfSpec.intervalId = statInterval.refreshRate
    perfSpec.metricId = [perfMetric_cpu]
    perfSpec.maxSample = 1

    result = client.sc.perfManager.QueryPerfComposite(querySpec=perfSpec)
    print "=======result=======", result


def get_perf_counter(client, counter_key_str="cpu.usage.average"):
    fm = "%s.%s.%s"
    pc_lst = client.sc.perfManager.perfCounter   
    for pc in pc_lst:
        key = pc.key
        g_key = pc.groupInfo.key
        n_key = pc.nameInfo.key
        u_key = pc.unitInfo.key
        stat_type = pc.statsType
        rollup_type = pc.rollupType
        if fm %(g_key, n_key, rollup_type) in [counter_key_str]:
            print "====counterid====", key
            return key
    raise Exception("Could not find Performance counter id, Key:%s" %(counter_key_str))

get_metrics_QueryPerfComposite(client, host)

####### ERROR ########

====counterid==== 2

====counterid==== 24

Traceback (most recent call last):

  File "esxi.py", line 156, in <module>

    get_metrics_

QueryPerfComposite(client, host)
  File "esxi.py", line 123, in get_metrics_QueryPerfComposite
    result = client.sc.perfManager.QueryPerfComposite(querySpec=perfSpec)
  File "/home/saju/cvt/trunk/src/cc/web/cc/psphere/__init__.py", line 352, in func
    **kwargs)
  File "/home/saju/cvt/trunk/src/cc/web/cc/psphere/client.py", line 57, in f
    return func(*args, **kwargs)
  File "/home/saju/cvt/trunk/src/cc/web/cc/psphere/client.py", line 219, in invoke
    result = getattr(self.service, method)(_this=_this, **kwargs)
  File "build/bdist.linux-x86_64/egg/suds/client.py", line 542, in __call__
  File "build/bdist.linux-x86_64/egg/suds/client.py", line 602, in invoke
  File "build/bdist.linux-x86_64/egg/suds/client.py", line 649, in send
  File "build/bdist.linux-x86_64/egg/suds/client.py", line 702, in failed
  File "build/bdist.linux-x86_64/egg/suds/bindings/binding.py", line 265, in get_fault
suds.WebFault: Server raised fault: 'A specified parameter was not correct.
metricId'


######### OUTPUT with perfMetric_cpu.instance = "" ########

====counterid==== 2
====counterid==== 24
=======result======= (PerfCompositeMetric){
   entity =
      (PerfEntityMetric){
         entity = <psphere.managedobjects.HostSystem object at 0xb4ef650>
         sampleInfo[] =
            (PerfSampleInfo){
               timestamp = 2012-09-11 00:02:04
               interval = 20
            },
         value[] =
            (PerfMetricIntSeries){
               id =
                  (PerfMetricId){
                     counterId = 2
                     instance = None
                  }
               value[] =
                  60,
            },
      }

Reply
0 Kudos
1 Reply
sajuptpm
Contributor
Contributor

It's working after commenting the code perfMetric_cpu.instance = "*"

Is it necessary to execute QueryPerfComposite method ???

def get_metrics_QueryPerfComposite(client, mob):
    statInterval = client.sc.perfManager.QueryPerfProviderSummary(entity=mob)
   
    perfMetric_cpu = client.create("PerfMetricId")
    perfMetric_cpu.counterId = get_perf_counter(client)
    #perfMetric_cpu.instance = "*"

    perfMetric_mem = client.create("PerfMetricId")
    perfMetric_mem.counterId = get_perf_counter(client, counter_key_str="mem.usage.average")
    #perfMetric_mem.instance = "*"

    perfSpec = client.create("PerfQuerySpec")
    perfSpec.entity = mob._mo_ref
    perfSpec.intervalId = statInterval.refreshRate
    perfSpec.metricId = [perfMetric_cpu, perfMetric_mem]
    perfSpec.maxSample = 1
   
    result = client.sc.perfManager.QueryPerfComposite(querySpec=perfSpec)
    print "=======result=======", result


def get_perf_counter(client, counter_key_str="cpu.usage.average"):
    """
    """
    fm = "%s.%s.%s"
    pc_lst = client.sc.perfManager.perfCounter   
    for pc in pc_lst:
        key = pc.key
        g_key = pc.groupInfo.key
        n_key = pc.nameInfo.key
        u_key = pc.unitInfo.key
        stat_type = pc.statsType
        rollup_type = pc.rollupType
        if fm %(g_key, n_key, rollup_type) in [counter_key_str]:
            print "====counterid====", key
            return key
    raise Exception("Could not find Performance counter id, Key:%s" %(counter_key_str))


host = HostSystem.get(client, name="192.168.0.105")
get_metrics_QueryPerfComposite(client, host)

======= OUTPUT ======

====counterid==== 2
====counterid==== 24
=======result======= (PerfCompositeMetric){
   entity =
      (PerfEntityMetric){
         entity = <psphere.managedobjects.HostSystem object at 0xadfe850>
         sampleInfo[] =
            (PerfSampleInfo){
               timestamp = 2012-09-11 18:21:40
               interval = 20
            },
         value[] =
            (PerfMetricIntSeries){
               id =
                  (PerfMetricId){
                     counterId = 2
                     instance = None
                  }
               value[] =
                  305,
            },
            (PerfMetricIntSeries){
               id =
                  (PerfMetricId){
                     counterId = 24
                     instance = None
                  }
               value[] =
                  8800,
            },
      }
   childEntity[] =
      (PerfEntityMetric){
         entity = <psphere.managedobjects.VirtualMachine object at 0xadfe6d0>
         sampleInfo[] =
            (PerfSampleInfo){
               timestamp = 2012-09-11 18:21:40
               interval = 20
            },
         value[] =
            (PerfMetricIntSeries){
               id =
                  (PerfMetricId){
                     counterId = 2
                     instance = None
                  }
               value[] =
                  264,
            },
            (PerfMetricIntSeries){
               id =
                  (PerfMetricId){
                     counterId = 24
                     instance = None
                  }
               value[] =
                  699,
            },
      },
}

Reply
0 Kudos