pcp
[Top] [All Lists]

Re: python pmapi interface

To: Stan Cox <scox@xxxxxxxxxx>
Subject: Re: python pmapi interface
From: fche@xxxxxxxxxx (Frank Ch. Eigler)
Date: Wed, 04 Apr 2012 12:47:15 -0400
Cc: pcp@xxxxxxxxxxx
In-reply-to: <4F7C76E2.2010507@xxxxxxxxxx> (Stan Cox's message of "Wed, 04 Apr 2012 12:29:22 -0400")
References: <4F7C76E2.2010507@xxxxxxxxxx>
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)
Hi, Stan -


scox wrote:
> [...]
> pm_code = pcp.pmNewContext()
> if (pm_code < 0):
>     print "PCP is not running"
>     exit

Some encoding of the error would be nice.  Is the context value hidden
inside the pm_code object, or inside the pcp library?  If the latter,
this would be a problem for apps that want to juggle between multiple
contexts.  Could pcp.pmNewContext() return a python context object
upon which further calls would be made?

> cpu_name = pcp.pmLookupName("hinv.ncpu")
> cpu_desc = pcp.pmLookupDesc(cpu_name)
> cpu_result = pcp.pmFetch(cpu_name)
> ncpu = pcp.pmExtractValue(cpu_result, cpu_desc, cpu_name[0], 0, "PM_TYPE_U32")

I wonder if it should be necessary to do all that
LookupDesc/Fetch/ExtractValue as separate steps.  Could these be
combined into a single

ncpu = pcp.pmFetch("hinv.ncpu" /* or array of same */,
                   [0] /* instances */,
                   PM_TYPE_U32 /* requested format */)

and have pmFetch internally do the pmLookupDesc / pmFetch / pmExtractValue?
(Or else have another combined function that does the same?)


> [...]
> metrics = ("kernel.all.load", "kernel.percpu.cpu.user", 
> "kernel.percpu.cpu.sys", "mem.freemem", "disk.all.total")
> metric_names = pcp.pmLookupName(metrics)
> metric_descs = pcp.pmLookupDesc(metric_names)

This vectorish approach looks nice!


- FChE

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