Webmin System stats git
Brought to you by:
gerbier
#!/usr/bin/perl -w
###############################################################################
# Webmin Sysstats - mem.pl.bsd
#
# Webmin Sysstats Module
# Copyright (C) 2002 by Eric Gerbier
# Bug reports to: gerbier@users.sourceforge.net
# $Id$
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
###############################################################################
use strict;
use warnings;
# to be used alone or from sysstat.pl without warning
# because require verify the path
require '../../gen-lib.pl' if ( !exists $ENV{WEBMINSTAT_TEMP} );
use RRDs;
my ( $mtotal, $mused, $stotal, $sused ) = ( 'U', 'U', 'U', 'U' );
my $pagesize = `sysctl -n vm.stats.vm.v_page_size`;
my $page_c = `sysctl -n vm.stats.vm.v_page_count`;
my $active_c = `sysctl -n vm.stats.vm.v_active_count`;
my $inactive_c = `sysctl -n vm.stats.vm.v_inactive_count`;
my $wired_c = `sysctl -n vm.stats.vm.v_wire_count`;
$mtotal = $pagesize * $page_c;
$mused = $pagesize * ( $active_c + $inactive_c + $wired_c );
my $fh_swap;
if ( open( $fh_swap, 'swapinfo -k |' ) ) {
( undef, undef, $sused, $stotal ) = split(/ +/) while (<$fh_swap>);
close($fh_swap);
$stotal <<= 10;
$sused <<= 10;
}
else {
warning("can not open swapinfo : $!");
}
debug("mem : mtotal=$mtotal mused=$mused stotal=$stotal sused=$sused");
RRDs::update( 'mem.rrd', "N:$mtotal:$mused:$stotal:$sused" );
my $ERR = RRDs::error();
warning("ERROR while updating mem.rrd: $ERR") if $ERR;