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_
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,
},
},
}