[Orca-dev] [patch] get procallator working with 2.6 kernel

Ian Holsman lists at holsman.net
Fri Aug 27 21:06:42 PDT 2004


for linux 2.6, the file format of /proc/meminfo has changed slightly.
it no longer has the 2 summary lines at the top.

This patch works for 2.4 & 2.6 kernels.. 
it might need some massaging to put it in the standard procallator, but here it is ...
regards
Ian

@@ -359,19 +370,38 @@ do {
    }
    # Get memory ocupation
    open (F_MEMINFO, "<$PROC/meminfo");
-   <F_MEMINFO>;
-   ($dumb, $mem_total,$mem_used,$mem_free,$mem_shrd,$mem_buff,$mem_cchd)=split /[^0-9]+/,<F_MEMINFO>;
-   ($dumb, $swp_total,$swp_used,$swp_free)=split /[^0-9]+/,<F_MEMINFO>;
+   my %meminfokeys;
+   while (<F_MEMINFO>) {
+      my ($key, $data) = split /:/;
+      chomp $data;
+      $data =~ s/^\s+(\d+).*$/$1/;
+      $meminfokeys{$key} = $data; #*1024;
+
+   }
    close (F_MEMINFO);
-   put_output ( "mem_used%",prcnt($mem_used,$mem_total),
-   		"mem_free%",prcnt($mem_free,$mem_total),
-		"mem_shrd%",prcnt($mem_shrd,$mem_total),
-		"mem_buff%",prcnt($mem_buff,$mem_total),
-   		"mem_cchd%",prcnt($mem_cchd,$mem_total),
-   		"swp_free%",prcnt($swp_free,$swp_total),
-		"swp_used%",prcnt($swp_used,$swp_total)
+   put_output( "mem_used%",prcnt( $meminfokeys{"MemTotal"} - $meminfokeys{"MemFree"}, $meminfokeys{"MemTotal"}),
+               "mem_free%",prcnt( $meminfokeys{"MemFree"}, $meminfokeys{"MemTotal"}),
+               "mem_buff%",prcnt( $meminfokeys{"Buffers"}, $meminfokeys{"MemTotal"}),
+               "mem_cchd%",prcnt( $meminfokeys{"Cached"}, $meminfokeys{"MemTotal"}),
+               "mem_actv%",prcnt( $meminfokeys{"Active"}, $meminfokeys{"MemTotal"}),
+               "swp_free%",prcnt( $meminfokeys{"SwapFree"}, $meminfokeys{"SwapTotal"}),
+               "swp_used%", prcnt($meminfokeys {"SwapTotal"} - $meminfokeys{"SwapFree"}, $meminfokeys{"SwapTotal"}),
+               "swp_cchd%", prcnt($meminfokeys {"SwapCached"}, $meminfokeys{"SwapTotal"})
    );
 




More information about the Orca-dev mailing list