[collectd] process stat plugin [was: New plugin developer documentation]

Florian Forster octo at verplant.org
Fri Apr 7 18:31:42 CEST 2006


Hello David,

On Fri, Apr 07, 2006 at 12:51:57AM -0700, David Bacher wrote:
> I am interested in a plugin like this. In fact I started to code it up
> before getting stuck with the problem of keeping track of which pids
> were threads of one process and which were actually distinct
> processes.

I assume you're talking about Linux, since other Kernels usually have
only one PID per _process_. Under Linux 2.6 you have a directory
`/proc/$pid/task' which lists `threads' within the same `process'.
Figuring out which LWPs belong together is not as easy as it could be,
though..

> Ideally, I'd like to keep track of the information from /proc/pid/stat
> only at the process level. That is, vm size, rss, cpu time, etc for a
> process with a particular name.

What about processes with the same name? I have a forking httpd, for
example, since PHP is not thread safe and for some weird reason people
like PHP.. I could imagine collecting:
- The number of processes with the same name (or, better yet, the same
  executable, though that might create problems with scritps).
- The aggregated 
  * vm size
  * rss
  * cpu time
  * ...

That way one can calculate the average (vm size, eg), the total (vm
size, eg), which should be the most interesting number about multiple
processes. Additionally we could think about collecting the minimum and
maximum {vm size, rss, cpu time, etc}. What do you think?

> Is there a way to know whether a given pid is a thread of some parent,
> or a distinct process? Does looking at the parent pid and tracing
> ancestry give enough information to make the distinction?

AfaIk:
- Go to /proc/$pid/task.
- Read all PIDs listen there and `handle them'. Save which PIDs have
  been handles already.
- The `process' (i.e. task leader) is the LWP whose PPID is _not_ in the
  task-list.
- Go to the next PID. Skip it, if it's in the list.

But that's more an assumption than knowledge.

Regards,
-octo
-- 
Florian octo Forster
Hacker in training
GnuPG: 0x91523C3D
http://verplant.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mailman.verplant.org/pipermail/collectd/attachments/20060407/bb4fa3ff/attachment.pgp


More information about the Collectd mailing list