Hi,
Rohan Arora <rarora2012@xxxxxxxxx> writes:
> I am using the Python API, and if I run a couple of mgFetch() calls
> using the MetricGroup class, and then use the metricConvert()
> function, I end up getting a value like 308.4132647893692. I had
> thought that to convert this rate converted value to a percentage, all
> I had to do was multiply by 100, but that would result in 30,800% of
> the CPU being used, and that is just by the user.
Assuming this is a continuation from your former thread, looking into
the metric description can help explain this;
% pminfo -dT kernel.all.cpu.user
kernel.all.cpu.user
Data Type: 64-bit unsigned int InDom: PM_INDOM_NULL 0xffffffff
Semantics: counter Units: millisec
Help:
total user CPU time from /proc/stat for all CPUs, including guest CPU
time
Notice the semantics lists it as a 'counter' metric, not a percentage,
so we can't simply multiply by 100 and call it a day. (check Section
2.3.3.2 in the PCP Programmer's Guide[1] for more details on semantics).
Second, the metricConvert() function doesn't convert from a counter
value to a percentage. Instead, it calculates the delta between the
most current value you've fetched and the previously stored value.
Therefore, you'll have to fetch the other various cpu states (`pminfo
kernel.all.cpu` on the commandline for a full list of them) and
calculate the percentage as a total of all the cpu counters.
Hope that helps,
Lukas
[1] - http://www.pcp.io/doc/pcp-programmers-guide.pdf
|