couchbaselabs/cbagent — pull request #1 by daverigby (2014-07-31 12:36:30+00:00)
Title: psstats: use `comm` instead of `cmd` field to prevent mis-identification...

... of processes

To gather RSS / VSIZE stats from a given named process, we execute a
ps command searching for a specific named process:

self.ps_cmd = "ps -eo pid,rss,vsize,cmd | " \
"grep {} | grep -v grep | sort -n -k 2 | tail -n 1"

However this is unreliable, as we use the `cmd` field to search
in. This contains the complete process command-line, which (in the
case of beam.smp) can include *other* process names in it's arguments
- for example:

11976 28200 1284088 /usr/lib/erlang/erts-5.10.4/bin/beam.smp -MMmcs30 ... memcached_port 12000 ...

(Note: above shortened for brevity).

Hence the beam.smp process can be mis-identified as memcached. Solve
this problem by using the `comm` field which is just the process name
(i.e. "beam.smp" in the above example) and hence prevent
mis-identification.