pcp
[Top] [All Lists]

Re: [pcp] Fetch User CPU Usage as a Percentage?

To: Nathan Scott <nathans@xxxxxxxxxx>
Subject: Re: [pcp] Fetch User CPU Usage as a Percentage?
From: Rohan Arora <rarora2012@xxxxxxxxx>
Date: Wed, 05 Aug 2015 17:13:28 +0000
Cc: Lukas Berk <lberk@xxxxxxxxxx>, 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=kEn2mcqOmVb331mcntxEIpLwlIi/BvTQZnbSteG1zTo=; b=DX/viTOfq8WgsvJelX8cZedOileNo7GKXsVsFtccVUr03dQjX/f4D9FCHaxEk9BcM8 hL61nyEScHCAgYty8PrZ3+2i93L535f408sTwTGMVAanKbvKo034B6d2diWKK3yFoqe6 cx5eu7fHECNMWF30/XgQ/fRnqifK4z1FjnroL6SNE4PLv8q/7bHo52TTVnxa5291LX7L v/b81GcX9glrP/exXswsvCk42W/RBxhyHsmekk50QHJuXbVCUSInQNZMH6f6zF4YHIlC 224h3YmvEPMv1W77GrVFcHah7pyY+XNf7jPM6Xa4MEkaUMJADiAHcENMaiKEQ/SVGFwj m30A==
In-reply-to: <CANbxzdVGc8i_9-z29Bb8dq+5VekS4KVCHX9jDBNdgc6=nZYPMQ@xxxxxxxxxxxxxx>
References: <CANbxzdXXmYefH5B1in5zYSkAT8gOieN387sNXDTvTR=9gyUNOw@xxxxxxxxxxxxxx> <87egjp3ffv.fsf@xxxxxxxxxx> <CANbxzdXrhBZO1fOKU+31a+mpTq1JDiNuhXO=QUEkyeKypD-aZg@xxxxxxxxxxxxxx> <CANbxzdWJPJwB0FtAnBtRe--XWKmaK4c9h5vJAhAZzF=GmUf3Hw@xxxxxxxxxxxxxx> <CANbxzdUaNPg6NV28OdAj+iOUNPBSb3mmvjOdUgrE8KFRCj8rqQ@xxxxxxxxxxxxxx> <CANbxzdXSZE3WrAOn5LXjdK1DZsevERMZ8xBo-KRMe1GPPxk-uw@xxxxxxxxxxxxxx> <1899659656.1423571.1438300850093.JavaMail.zimbra@xxxxxxxxxx> <CANbxzdVd42n9nVZuGajmdRq3PPcU=8=cS8VMxTk==mw4QycfHA@xxxxxxxxxxxxxx> <849907258.4457090.1438733991270.JavaMail.zimbra@xxxxxxxxxx> <CANbxzdVGc8i_9-z29Bb8dq+5VekS4KVCHX9jDBNdgc6=nZYPMQ@xxxxxxxxxxxxxx>
So, I have kind of got something working running the following code:
  metrics = (
   Â"mem.physmem",
   Â"mem.util.used",
   Â"kernel.all.cpu.user"
  )

  m_group = pmcc.MetricGroup(pmcc.MetricCache(PM_CONTEXT_HOST, "hostname"))
  m_group.mgAdd(metrics)

  m_group.mgFetch()
  sleep(1)
  m_group.mgFetch()

  print m_group["kernel.all.cpu.user"].metricConvert(m_group.mgDelta())

And I get the following as a result:
 ÂÂ[(<pcp.pmapi.pmValue object at 0x27d8c20>, '', 308.4132647893692)]

I have a couple of questions about what the result of calling metricConvert() gives me. The second value is supposed to be the name, which in this case should be "kernel.all.cpu.user" correct? Also, what are the units for the last value? I see in the code that it is (value - pvalue) / delta but what does that number tell me? What do I do to that number to turn it into a percentage?

Thanks,
Rohan

On Wed, Aug 5, 2015 at 9:30 AM Rohan Arora <rarora2012@xxxxxxxxx> wrote:
I had the versions of the files from 3.10.5. I just grabbed the latest versions from github, now seeing a lot of things that were missing before. Thanks!

Best,
Rohan

On Tue, Aug 4, 2015 at 8:19 PM Nathan Scott <nathans@xxxxxxxxxx> wrote:


----- Original Message -----
> I looked through the file and I am confused about a couple of things. I
> didn't see a builder()

src/python/pcp/pmcc.py line 548

> or run() method in the pmcc.py file,

line 608 of same file. Are you using a (very) old version of PCP perhaps?
See "git.pcp.io/pcp master" for a current version, these methods have been
there for quite some time though.

> and I wasn't
> really sure what was happening in these functions, aside from the obvious.
> Where is the source for these two functions? Also, is it required to build
> a MetricGroupManager as shown in pcp-iostat.py? Am I able to just use
> MetricGroup objects instead of using a MetricGroupManager?

Pretty sure you can build your own - just see the MetricGroupManager code
and how it manages things, and re-implement/re-use as you see fit.

cheers.

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