Get memory info on freebsd
authorJamie Cameron <jcameron@webmin.com>
Tue, 20 May 2008 16:25:40 +0000 (16:25 +0000)
committerJamie Cameron <jcameron@webmin.com>
Tue, 20 May 2008 16:25:40 +0000 (16:25 +0000)
proc/CHANGELOG
proc/freebsd-lib.pl

index 303b4a8..c451c6e 100644 (file)
@@ -15,3 +15,5 @@ Free and used real and virtual memory is now displayed on Solaris.
 ---- Changes since 1.390 ----
 Re-wrote the user interface using the new Webmin UI library, for consistency.
 Re-designed the Run and Search pages, and made the search radio buttons auto-selecting.
+---- Changes since 1.410 ----
+Added physical memory display on FreeBSD.
index c84735a..ccefae5 100644 (file)
@@ -94,5 +94,29 @@ local ($ptyfh, $ttyfh, $pty, $tty) = @_;
 ioctl($ttyfh, 536900705, 0);
 }
 
+# get_memory_info()
+# Returns a list containing the real mem, free real mem, swap and free swap
+# (In kilobytes).
+sub get_memory_info
+{
+my $sysctl = {};
+my $sysctl_output = &backquote_command("/sbin/sysctl -a 2>/dev/null");
+return ( ) if ($?);
+foreach my $line (split(/\n/, $sysctl_output)) {
+       if ($line =~ m/^([^:]+):\s+(.+)\s*$/s) {
+               $sysctl->{$1} = $2;
+               }
+       }
+return ( ) if (!$sysctl->{"hw.physmem"});
+my $mem_inactive = $sysctl->{"vm.stats.vm.v_inactive_count"} *
+                  $sysctl->{"hw.pagesize"};
+my $mem_cache = $sysctl->{"vm.stats.vm.v_cache_count"} *
+               $sysctl->{"hw.pagesize"};
+my $mem_free = $sysctl->{"vm.stats.vm.v_free_count"} *
+              $sysctl->{"hw.pagesize"};
+return ( $sysctl->{"hw.physmem"},
+        $mem_inactive + $mem_cache + $mem_free );
+}
+
 1;