Hello, i trie to get the Energy-Information from an single ESXi Host via the PerformanceManager. (see attached picture)
I used Onyx Proxy to get the Informations which classes are used there.
I used as basic this example: https://communities.vmware.com/thread/419294 and modified a little bit to a single query.
This is my code of a Scriptable Task (Input to this Scriptable Task is a single Host (VC:HostSystem) named: host) :
var currentTime = System.getCurrentTime(); // reduce 15 Minutes var startTime = currentTime - (900 * 1000); var myEndDate = new Date(); myEndDate.setTime(currentTime); var myStartDate = new Date(); myStartDate.setTime(startTime); // https://communities.vmware.com/thread/419294 var myQuery = new Array(); myQuery[0] = new VcPerfQuerySpec(); myQuery[0].startTime = myStartDate; myQuery[0].endTime = myEndDate; myQuery[0].format = VcPerfFormat.normal; myQuery[0].entity = host.reference; myQuery[0].intervalId = 20; myQuery[0].metricId = host.sdkConnection.perfManager.queryAvailablePerfMetric(host.reference,null,null,20); /* Return Type: VcPerfEntityMetricBase[] -> Base type for the various VcPerfEntityMetric encodings. */ var result = host.sdkConnection.perfManager.queryPerf(myQuery); for(var i in result) { var perfMetricSeries = result[i].value; //VcPerfMetricSeries[] var perfSampleInfo = result[i].sampleInfo; //VcPerfSampleInfo[] for(var j in perfSampleInfo) { //System.log(j+"->"+perfSampleInfo[j].timestamp); } var y = 0; for(var k in perfMetricSeries) { if(host.sdkConnection.perfManager.perfCounter[perfMetricSeries[k].id.counterId] != null) { var labelInfo = host.sdkConnection.perfManager.perfCounter[perfMetricSeries[k].id.counterId].nameInfo.label var groupInfo = host.sdkConnection.perfManager.perfCounter[perfMetricSeries[k].id.counterId].groupInfo.label; var unitInfo = host.sdkConnection.perfManager.perfCounter[perfMetricSeries[k].id.counterId].unitInfo.label; if(unitInfo == "Joule") { // this was a try to find which Group / Label has "Joule" as unit //System.log("Group: "+groupInfo+ " - "+ labelInfo); } if(groupInfo == "Power") { // this wa a test to see what is in the group "Power" // System.log("Label: " +labelInfo +" - "+ unitInfo); } if(perfMetricSeries[k].id.counterId == 314) { // CounterID 314 was displayed in Onyx Proxy System.log("314!!!! Group: "+groupInfo+ " - "+ labelInfo +" - "+ unitInfo); } if(groupInfo == "Power" && labelInfo == "Host Power Capacity Provisioned" && unitInfo =="Percent") { System.log("Power -> Host Power Capacity Provisioned -> Percent") var m = 0; for(var z in perfMetricSeries[k].value) { if(perfMetricSeries[k].value[z] != 0 && perfMetricSeries[k].value[z]!= "0") { System.log(m+"->"+perfMetricSeries[k].value[z]); m++; } } } if(groupInfo == "Power" && labelInfo == "Energy usage" && unitInfo =="Joule") { System.log("Power -> Energy usage -> Joule") // System.log(y + "-> Power"); y++; var m = 0; for(var z in perfMetricSeries[k].value) { if(perfMetricSeries[k].value[z] != 0 && perfMetricSeries[k].value[z]!= "0") { System.log(m+"->"+perfMetricSeries[k].value[z]); m++; // System.log(perfSampleInfo[k].timestamp[z]); } } } if(groupInfo == "System" && labelInfo == "Resource memory zero" && unitInfo =="KB") { System.log("System - Resource memory zero - KB") var m = 0; for(var z in perfMetricSeries[k].value) { if(perfMetricSeries[k].value[z] != 0 && perfMetricSeries[k].value[z]!= "0") { System.log(m +"->"+perfMetricSeries[k].value[z]); m++; } } } } } }
After now hours of testing I have a few Questions:
If you have a value of the Type VCPerfCounterInfo.unitInfo "Percent" (https://www.vmware.com/support/orchestrator/doc/vco_vsphere55_api/html/VcPerfCounterInfo.html#key ) why is that somewhere around 10 000 000 ? In my case the "Host Power Capacity Provisioned" was between 9 700 000 and 9 900 000.
groupInfo == "Power" && labelInfo == "Energy usage" && unitInfo =="Joule"
This was my first try because i exspected that the informations i'm looking for are storred here - but it is a static value about 1975. I think it is the power of the two 1000 watt PowerSupplys of the host. Correct?
groupInfo == "System" && labelInfo == "Resource memory zero" && unitInfo =="KB"
Well, Onyx displayed correct that this are the values I were looking in the vCenter chart - what has "Resource memory zero" to do with the energy that the host is using? Are that real datas or only calculated?