pcp
[Top] [All Lists]

Re: [pcp] Help with Python API

To: Nathan Scott <nathans@xxxxxxxxxx>
Subject: Re: [pcp] Help with Python API
From: Rohan Arora <rarora2012@xxxxxxxxx>
Date: Mon, 29 Jun 2015 17:45:59 +0000
Cc: "pcp@xxxxxxxxxxx" <pcp@xxxxxxxxxxx>
Delivered-to: pcp@xxxxxxxxxxx
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-type; bh=Bte6ZbA5lq7IzigHfduCx6xYP90qr+XyVBFl87QyBUw=; b=LgN8Sn+WRRnZ5xImz1H4hTcr4kVKIeXdnv7joWT4ASA1hQl8NKS8CpLZbC2Gnek8tF 7O/OLgvOVQGZJJT47YhrU7uhluQ+ESYHwzsg0NG0JzeA4EHamGpUrGrN7KoTdCImxoz5 u1qkFAaPcd5hv1j+vexVq6vQoG2klfTi5swhlLnPqNeTTXOFdLxNj0X2KYvNijjmHlov SqQpAJz6xylLqqlibnCdASMarMMinh0HYpReAGSxr8ch4DwcWcUPgKpI+TuzX1rmMIn4 izavvbVajylbGBBeLvtsXnZjAQZ+bKONl7lb70DNaHOIBof4xFcR5L2+zww3ynf7apxt cgrQ==
In-reply-to: <587447889.27462536.1435530714712.JavaMail.zimbra@xxxxxxxxxx>
References: <CANbxzdXmsRFyF_J_7c93uBuKWJHZikoRs6xmSPQC91rALtZbNA@xxxxxxxxxxxxxx> <1340154579.26424419.1435278070481.JavaMail.zimbra@xxxxxxxxxx> <CANbxzdX2tGtGmRvyVFL7h0dXFPLcqYCAgbLEqQspdt7-vdH00A@xxxxxxxxxxxxxx> <CANbxzdUCUZcj4pF32CufxXAt452WUhJkCcjOT+XLZ+4pgcmNsg@xxxxxxxxxxxxxx> <CANbxzdXGZosHkKZXrcvJMoaPb=2YOY7_Rhw6cs2y-vp0Jhj8Vg@xxxxxxxxxxxxxx> <CANbxzdXVmBE1qRoHQQTy9VvbAt4rqppwEL-xizSUH7cKOswNzQ@xxxxxxxxxxxxxx> <CANbxzdV7Vndvczvo9OLgc8CpQ20wBK=YUD6v87ewVBa6yrTXKQ@xxxxxxxxxxxxxx> <CANbxzdXcqg=sRYa0JwETB+RHChw42uAeZE-n+bABUjV-FD9TDg@xxxxxxxxxxxxxx> <587447889.27462536.1435530714712.JavaMail.zimbra@xxxxxxxxxx>
I'm having difficulty finding documentation on how to use pmcc and it's functions. Can you point me to a man page, or any other documentation?

Would the results of using pmcc be any different than using pmapi.py directly? Right now I have it so that I am fetching metrics from an archive using pmFetch, and I put the values into a Python dictionary manually. Would using pmcc allow me to do this much more easily/with significantly less code?

I tried looking through the pmcc.py file to figure it out, but I am unsure about how to actually use it. Do I need to use the MetricGroupManager class, or do I use the MetricGroup class directly if I have a set list of metrics that I want to be able to retrieve data from. Also, how do make it use the PM_CONTEXT_ARCHIVE type instead of PM_CONTEXT_HOST? It looks like it defaults to host, does it know to use archive if the context used for creating the MetricCache had type archive? Also, if I use the MetricGroupManager, how would I fetch again? MetricGroup has the mgFetch function, but I don't see how I could call it with a MetricGroupManager instance.

Thanks,
Rohan

On Sun, Jun 28, 2015 at 6:31 PM Nathan Scott <nathans@xxxxxxxxxx> wrote:
Hi Rohan,

----- Original Message -----
> How is the number for the cpu metrics calculated? For example, if the
> kernel.all.cpu.idle value is 122282400, how is that number interpreted?
> Right now, to estimate it as a percentage, I add the values for idle, sys,
> and user, and add them together. I then calculate the actual percentage as
> idle / (idle + user + sys). Is there a better way to do this, like some
> function built into the API that I didn't see?
>

Its a value in milliseconds, since the machine booted (exactly as the kernel
passes to userspace)...

$ pminfo -dtT kernel.all.cpu.idle

kernel.all.cpu.idle [total idle CPU time from /proc/stat for all CPUs]
  Data Type: 64-bit unsigned int InDom: PM_INDOM_NULL 0xffffffff
  Semantics: counter Units: millisec
Help:
total idle CPU time from /proc/stat for all CPUs


It depends what you want to do with the final value, but usually interpreting
such a value (note - "Semantics: counter") requires two samples at different
times (i.e. 2 pmFetch calls, with different result->timestamps). This is
then "rate converted" - i.e. we look at the change in value divided by the
change in time. Percentage utilisation can be then calculated by multiplying
by 100.

The pcp.pmcc python module will help you with some of this (it keeps track of
multiple values when needed, across samples, for each metric).

cheers.

--
Nathan
<Prev in Thread] Current Thread [Next in Thread>