VMware {code} Community
Fisk
Contributor
Contributor

Adding A Performane Counter to a MOR

I"m able to successfully pull performance data for counters already assigned to a MOR but I don't see how you can assign a new counter. Do you need to create a new Interval? How do you assign it to a MOR?

Specifically I'm attempting to assign the cpu.ready.summation counter to a HostMOR and pull back performance information through C#.

r/s

Fisk

Reply
0 Kudos
5 Replies
arpitmpatel13
Enthusiast
Enthusiast

Hi,

Note that some of counters are specific to VMs and some counters are specific to ESX Host.

cpu.ready.summation is related to VM's mor. So you would not be able to collect the same for Host Mor.

Thanks

Please mark if helpful...

Fisk
Contributor
Contributor

Thanks that helps.

I now see that the %Ready counter is only available on vmMOR's on a "Per CPU Instance only". Do you know which property I need to pull from the vmMOR and pass into the QueryPerf in order to retrieve those statistics?

Thanks again,

Fisk

Reply
0 Kudos
arpitmpatel13
Enthusiast
Enthusiast

In queryperf you will need to pass PerfManager (which will be common for all metrics) and PerfQuerySpec array(which you can build using PerfMetricIDs assiciated with the counter of your interest)

Thanks

Please mark if helpful...

Fisk
Contributor
Contributor

Thanks for the help but I still have a couple questions.

I'm already able to pull performance information from vmMOR objects but I thought you could only pull information from counters which are returned from the QueryAvailablePerfMetric method. When you query using this method referencing a vmMOR you do not recieve the cpu.ready.summation counter. Can you pass this counter into the queryspec regardless and recieve the stat? From the performance counter documentation it looks like I need to pass the specific CPU Instance Entity for that vmMOR....does this make sense? Where do you pull that Instance infromation?

Here is the code I'm running currently.

public void findPerformanceDetails( ManagedObjectReference targetMOR )

{

Console.WriteLine("Findind Performance Information on Entity " + targetMOR.Value + " Entity Type = " + targetMOR.type);

Console.WriteLine("");

int intervalID = 300;

int counterID;

int key;

String group;

String name;

String rollup;

DateTime curTime = _vimServiceSession.CurrentTime(serviceInstObjRef);

DateTime beginTime = curTime.Subtract(new TimeSpan(1,0,0,0));

DateTime endTime = curTime;

string[] arrProps = new string[] { "perfCounter" };

Object[] obInfo = getObjectProperties(_perforManager, arrProps);

PerfCounterInfo[] cInfo = (PerfCounterInfo[])obInfo[0];

Hashtable PerfByID = new Hashtable();

for (int i = 0; i < cInfo.Length; i++)

{

key = cInfo[i].key;

group = cInfo[i].groupInfo.key;

name = cInfo[i].nameInfo.key;

rollup = cInfo[i].rollupType.ToString();

if (group == "cpu")

Console.WriteLine("ID: " + key + " group: " + group + "." + name + "." + rollup);

PerfByID.Add(key, group + "." + name + "." + rollup);

}

Console.WriteLine("");

// Using QueryPErfProviderSummary for a targetMOR(Host/VM/Etc) to see if it accepts live update queries.

PerfProviderSummary perfSum = vimServiceSession.QueryPerfProviderSummary(perforManager, targetMOR);

//Console.WriteLine("Refresh Rate " + perfSum.refreshRate + "\nCurrentSupported :"

// + perfSum.currentSupported + "\nisSummarySupported :" + perfSum.summarySupported);

Console.WriteLine("");

// Using QueryAvailablePerfMetric to determine which counters can be pulled for the targetMOR.

PerfMetricId[] perID = vimServiceSession.QueryAvailablePerfMetric(perforManager, targetMOR, beginTime, false, endTime, false, intervalID, true);

//Console.WriteLine("QueryAvailablePerf length = " + perID.Length);

//Console.WriteLine("");

foreach (var perfMetric in perID)

{

Console.WriteLine("PerfMetric.CounterID = " + perfMetric.counterId);

Console.WriteLine("Counter group.name.rollup = " + PerfByID[http://perfMetric.counterId|http://perfMetric.counterId]);

//DynamicProperty dp = perfMetric.dynamicProperty;

//Console.WriteLine("PerfMetric.Instance = " + perfMetric.nameInfo.summary);

}

// Console.WriteLine("");

// Using QueryPerf to gather statics on counters passed in perfqueryspec via metricID.

PerfQuerySpec[] qSpec = new PerfQuerySpec[] { new PerfQuerySpec() };

qSpec[0].entity = targetMOR;

qSpec[0].metricId = perID;

qSpec[0].intervalId = intervalID;

qSpec[0].startTime = beginTime;

qSpec[0].endTime = endTime;

qSpec[0].startTimeSpecified = true;

qSpec[0].endTimeSpecified = true;

qSpec[0].maxSample = 1;

qSpec[0].maxSampleSpecified = true;

//PerfEntityMetricBase[] perfMORObj = vimServiceSession.QueryPerf(perforManager, qSpec);

PerfCompositeMetric vmChildStats = vimServiceSession.QueryPerfComposite(perforManager, qSpec[0]);

PerfEntityMetricBase[] perfMORObj = vmChildStats.childEntity;

Console.WriteLine("Number child entities found = " + perfMORObj.Length);

if(perfMORObj != null && perfMORObj.Length > 0)

{

// PerfCounterInfo perfinfo = perfMORObj[0];

//Console.WriteLine("Here it is. " + perfinfo.nameInfo.summary);

for (int a = 0; a < perfMORObj.Length; ++a)

{

PerfEntityMetric perMetVal = (PerfEntityMetric)perfMORObj[a];

PerfMetricSeries[] perfVal = perMetVal.value;

Console.WriteLine("Target entity value = " + perMetVal.entity.Value);

if (perfVal != null)

{

Console.WriteLine("Perf Counters fetched");

Console.WriteLine("");

for (int b = 0; b < perfVal.Length; ++b)

{

PerfMetricSeries pmCSV = perfVal[b];

PerfMetricIntSeries intVal = (PerfMetricIntSeries)perfVal[b];

if (PerfByID[perfVal[http://b].id.counterId|http://b].id.counterId].ToString().StartsWith("cpu"))

{

Console.WriteLine("perfval = " + pmCSV.id.counterId.ToString());

Console.WriteLine("Rollup = " + PerfByID[perfVal[http://b].id.counterId|http://b].id.counterId]);

Console.WriteLine("Value = " + intVal.value);

}

long[] stat = intVal.value;

foreach (long lng in stat)

{

if (PerfByID[perfVal[http://b].id.counterId|http://b].id.counterId].ToString().StartsWith("cpu"))

{

Console.Write(lng + " ");

}

}

Console.WriteLine("");

}

}

else

Console.WriteLine("perfVal = Null");

}

}

}

Reply
0 Kudos
Fisk
Contributor
Contributor

The problem was the statistic level was not set high enough over the interval I was querying from. This was not documented very well in the SDK but the below post was great.

http://communities.vmware.com/docs/DOC-5230

Reply
0 Kudos