title: Linux "top" command - want to aggregate resource usage to the process group or user name, especially for postgres
body: <p>An important topic in software deveopment / programming is to assess the size of the product, and to <strong>match the application footprint to the system</strong> where it is running.  One may need to optimize the product, and/or one may need to add more memory, use a faster processor, etc.  In the case of virtual machines, it is important to make sure the application will work effectively by perhaps making the VM memory size larger, or allow a product to get more resources from the hypervisor when needed and available.</p>
  
  <p>The <strong>linux top(1) command</strong> is great, with its ability to sort by different fields, add optional fields, highlight sort criteria on-screen, and switch sort field with &lt; and >. On most systems though, there are very many processes running, making "at-a-glance" examination a little difficult.  Consider: </p>
  
  <pre><code>  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+   PPID SWAP nFLT COMMAND                                                                                                                                                        
   2181 root      20   0 7565m 3.2g 7028 S  2.7 58.3  86:41.17     1 317m  10k java                                                                                                                                                           
   1751 root      20   0  137m 2492 1056 S  0.0  0.0   0:02.57     1 5104   76 munin-node                                                                                                                                                                                                                                                                                                                
  11598 postgres  20   0  146m  23m  11m S  0.0  0.4   7:51.63  2143 3600   28 postmaster                                                                                                                                                     
   1470 root      20   0  243m 1792  820 S  0.0  0.0   0:01.89     1 2396   23 rsyslogd                                                                                                                                                       
   3107 postgres  20   0  146m  26m  11m S  0.0  0.5   7:40.61  2143  936   58 postmaster                                                                                                                                                     
   3168 postgres  20   0  132m  14m  11m S  0.0  0.2   8:27.27  2143  904   53 postmaster                                                                                                                                                     
   3057 postgres  20   0  138m  19m  11m S  0.0  0.3   6:55.63  2143  856   36 postmaster                                                                                                                                                     
   3128 root      20   0 85376  900  896 S  0.0  0.0   0:00.11  1636  852    2 sshd                                                                                                                                                           
   1728 root      20   0 80860 1080  952 S  0.0  0.0   0:00.61     1  776    0 master                                                                                                                                                         
   3130 manager   20   0 85532  844  672 S  0.0  0.0   0:01.03  3128  712   36 sshd                                                                                                                                                           
    436 root      16  -4 11052  264  260 S  0.0  0.0   0:00.01     1  688    0 udevd                                                                                                                                                          
   2211 root      18  -2 11048  220  216 S  0.0  0.0   0:00.00   436  684    0 udevd                                                                                                                                                          
   2212 root      18  -2 11048  220  216 S  0.0  0.0   0:00.00   436  684    0 udevd                                                                                                                                                          
   1636 root      20   0 66176  524  436 S  0.0  0.0   0:00.12     1  620   25 sshd                                                                                                                                                           
   1486 root      20   0  229m 2000 1648 S  0.0  0.0   0:00.79  1485  596  116 sssd_be                                                                                                                                                        
   2306 postgres  20   0  131m  11m   9m S  0.0  0.2   0:01.21  2143  572   64 postmaster                                                                                                                                                     
   3055 postgres  20   0  135m  16m  11m S  0.0  0.3  10:18.88  2143  560   36 postmaster
  </code></pre>
  
  <p>...etc... This is for about 20 processes, but there are well over 100 processes.                                                                                                                                                     </p>
  
  <p>In this example I was sorting by SWAP field.</p>
  
  <p>I would like to be able to aggregate related processes based on the "process group" of which they are a part, or based on the USER running the process, or based on the COMMAND being run. Essentially I want to:</p>
  
  <ul>
  <li><strong>Aggregate by PPID</strong>, or</li>
  <li><strong>Aggregate by USER</strong>, or</li>
  <li><strong>Aggregate by COMMAND</strong>, or</li>
  <li><strong>Turn off aggregation</strong></li>
  </ul>
  
  <p>This would allow me to see more quickly what is going on.  The expectation is that all the postgres processes would show up together, as a single line, with process group leader (2143, not captured in the snippet) displaying aggegated metrics.  Generally the aggregation would be a sum (VIRT, RES, SHR, %CPU, %MEM, TIME+, SWAP, nFLT), but sometimes not (as for PR and NI, which might be shown as just --).</p>
  
  <p>For processes whose PPID is 1, it would be nice to have an option of toggling between aggregating them all together, or of leaving them listed individually.</p>
  
  <p>Aggegation by the name of the process (java vs. munin-node, vs. postmaster, vs. chrome) would also be a nice option.  The COMMAND arguments would not be used when aggregating by command name. </p>
  
  <p>This would be very valuable when tuning an application. <strong>How can I do this, aggregating top data for at-a-glance viewing in larger scale systems?</strong>  Has anyone written an app, perhaps that uses top in batch mode, to create a summary view like I'm discussing?</p>
  
  <p>FYI, I'm specifically interest in something for CentOS, but this would be helpful on any OS variant.</p>
  
  <p>Thanks!
  ...Alan</p>