From 715fa529795f46ee8753fd93d2bedf54b3be7026 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Tue, 16 Apr 2013 21:18:57 -0700 Subject: [PATCH] Collect swap usage on BSD --- proc/freebsd-lib.pl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/proc/freebsd-lib.pl b/proc/freebsd-lib.pl index acfcd8a1b..55026fb83 100755 --- a/proc/freebsd-lib.pl +++ b/proc/freebsd-lib.pl @@ -114,8 +114,20 @@ 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"}; + +my ($swapinfo_output) = &backquote_command("/usr/sbin/swapinfo"); +my ($swap_total, $swap_free) = (0, 0); +foreach my $line (split(/\n/, $swapinfo_output)) { + if ($line =~ /^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)/) { + $swap_total += $2 * 1024; + $swap_free += $4 * 1024; + } + } + return ( $sysctl->{"hw.physmem"} / 1024, - ($mem_inactive + $mem_cache + $mem_free) / 1024 ); + ($mem_inactive + $mem_cache + $mem_free) / 1024, + $swap_total, + $swap_free ); } 1;