Author: James Page <james.page@ubuntu.com>
Description: [PATCH] Updates to deal with procps >= 3.3 as present in Debian
 unstable
Origin: https://github.com/javacruft/extras-memory-monitor/commit/7ba8e783a9936a3b59abd840f516c741ee9ea3b9
Forwarded: yes

Index: jenkins-memory-monitor/src/main/java/org/jvnet/hudson/Top.java
===================================================================
--- jenkins-memory-monitor.orig/src/main/java/org/jvnet/hudson/Top.java	2012-02-21 11:51:10.427331352 +0000
+++ jenkins-memory-monitor/src/main/java/org/jvnet/hudson/Top.java	2012-05-29 11:28:29.586027313 +0100
@@ -109,7 +109,13 @@
                     try {
                         Matcher m = p.matcher(line);
                         if(m.find()) {
-                            values[i] = parse(m.group(1));
+                            if (m.groupCount() == 2) {
+                               // Deal with later versions of procps
+                               // which split KMG from values
+                               values[i] = parse(m.group(2) + m.group(1));
+                            } else {
+                               values[i] = parse(m.group(1));
+                            }
                             continue OUTER;
                         }
                     } catch (NumberFormatException e) {
@@ -161,6 +167,31 @@
  6907 kohsuke   20   0  134m  14m 9184 S    2  0.4   0:51.56 metacity
 
 
+On Debian Sid 29/05/2012
+====================================
+Linux hendrix 3.2.0-24-generic #39-Ubuntu SMP Mon May 21 16:52:17 UTC 2012 x86_64 GNU/Linux
+/usr/bin/top
+top - 11:24:47 up  2:43,  0 users,  load average: 0.13, 0.52, 0.77
+Tasks: 224 total,   2 running, 221 sleeping,   0 stopped,   1 zombie
+%Cpu(s):  1.5 us,  9.4 sy,  0.0 ni, 89.0 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st
+KiB Mem:   3980564 total,  2757216 used,  1223348 free,   193496 buffers
+KiB Swap:  4124668 total,      256 used,  4124412 free,  1004884 cached
+
+  PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND
+ 1607 root      20   0  494m 140m 115m S  18.3  3.6   3:54.94 Xorg
+ 3452 jamespag  20   0 1431m 563m  42m S  12.2 14.5   1:11.48 thunderbird-bin
+26657 jamespag  20   0 23616 1540 1096 R  12.2  0.0   0:00.02 top
+
+MEMORY Usage
+This portion consists of two lines which may express values in kilobytes (Kb), megabytes (Mb) 
+or gigabytes (Gb)  depending  on  the  amount  of  currently
+installed physical memory.
+
+Line 1 reflects physical memory, classified as:
+    total, used, free, buffers
+
+Line 2 reflects virtual memory, classified as:
+    total, used, free, cached
 
 From http://www.unixtop.org/about.shtml
 =======================================
@@ -260,25 +291,29 @@
         new Pattern[] {
             Pattern.compile("^mem(?:ory)?:.* ([0-9.]+[kmgb]) phys mem"), // Sol10+blastwave
             Pattern.compile("^mem(?:ory)?:.* ([0-9.]+[kmgb]) total"), // Linux
+            Pattern.compile("^([kmg])(?:i)?b mem(?:ory)?:.* ([0-9.]+) total"), // Linux procps (>= 3.3)
             Pattern.compile("^mem(?:ory)?:.* ([0-9.]+[kmgb]) real") // unixtop.org
         },
 
         // available phys. memory
         new Pattern[] {
             Pattern.compile("^mem(?:ory)?:.* ([0-9.]+[kmgb]) free"),
+            Pattern.compile("^([kmg])(?:i)?b mem(?:ory)?:.* ([0-9.]+) free"), // Linux procps (>= 3.3)
             Pattern.compile("^physmem:.* ([0-9.]+[kmgb]) free")  // Mac OS X
         },
 
         // total swap memory
         new Pattern[] {
             Pattern.compile("^mem(?:ory)?:.* ([0-9.]+[kmgb]) swap,"), // Sol10+blastwave
-            Pattern.compile("^swap:.* ([0-9.]+[kmgb]) total") // Linux
+            Pattern.compile("^swap:.* ([0-9.]+[kmgb]) total"), // Linux
+            Pattern.compile("^([kmg])(?:i)?b swap:.* ([0-9.]+) total") // Linux procps (>= 3.3)
         },
 
         // available swap memory
         new Pattern[] {
             Pattern.compile("^mem(?:ory)?:.* ([0-9.]+[kmgb]) free swap"), // Sol10+blastwave
             Pattern.compile("^swap:.* ([0-9.]+[kmb]) free"), // Linux
+            Pattern.compile("^([kmg])(?:i)?b swap:.* ([0-9.]+) free"), // Linux procps (>= 3.3)
             Pattern.compile("^swap:\\w* (?:[0-9.]+[kmb])\\w* \\+ \\w*([0-9.]+[kmb]) free"), // Mac OS
             Pattern.compile("^mem(?:ory)?:.* ([0-9.]+[kmgb]) swap free")  // unixtop
         },
