[go: up one dir, main page]

Menu

[3eb72d]: / mem.pl  Maximize  Restore  History

Download this file

112 lines (97 with data), 3.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/perl -w
###############################################################################
# Webmin Sysstats - mem.pl
#
# 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
if ( !exists $ENV{WEBMINSTAT_TEMP} ) {
use FindBin;
use lib "$FindBin::Bin/../..";
require 'sysstats-aquisition-lib.pl';
}
use RRDs;
my $info = '/proc/meminfo';
###############################################################################
# fix for 2.6 kernel : MemShared does not exist any more, so set it to 0
# to avoid some undefined values
my (
$mem_total, $mem_used, $swap_total, $swap_used,
$mem_shared, $mem_buffers, $mem_cached
) = ( 'U', 'U', 'U', 'U', 0, 'U', 'U' );
my ( $swap_free, $mem_free );
my $fh_proc;
if ( open( $fh_proc, '<', $info ) ) {
while (<$fh_proc>) {
# old code : do not work on 2.6 kernels
# if (m/^Mem:/) {
# my @tab = split;
# $mtotal = $tab[1];
# $mused = $tab[2] - $tab[5] - $tab[6];
# $mshared = $tab[4];
# $mbuffers = $tab[5];
# $mcached = $tab[6];
# }
# elsif (m/^Swap:/) {
# my @tab = split;
# $stotal = $tab[1];
# $sused = $tab[2];
# }
# new code , compatible with 2.6 kernel
if (m/^MemTotal:\s*(\d+)/) {
$mem_total = $1;
}
elsif (m/^MemFree:\s*(\d+)/) {
$mem_free = $1;
}
elsif (m/^Buffers:\s*(\d+)/) {
$mem_buffers = $1;
}
elsif (m/^Cached:\s*(\d+)/) {
$mem_cached = $1;
}
elsif (m/^MemShared:\s*(\d+)/) {
$mem_shared = $1;
}
elsif (m/^SwapTotal:\s*(\d+)/) {
$swap_total = $1;
}
elsif (m/^SwapFree:\s*(\d+)/) {
$swap_free = $1;
}
}
close($fh_proc);
}
else {
warning("can not open $info : $!");
}
#debug(
#"mem : memtotal=$mtotal memused=$mused memshared=$mshared membuffer=$mbuffers memcached=$mcached swaptotal=$stotal swapused=$sused" );
$swap_used = $swap_total - $swap_free;
$mem_used = $mem_total - $mem_free - $mem_buffers - $mem_cached;
debug(
"mem : memtotal=$mem_total memused=$mem_used memshared=$mem_shared membuffer=$mem_buffers memcached=$mem_cached swaptotal=$swap_total swapused=$swap_used"
);
RRDs::update( 'mem.rrd', "N:$mem_total:$mem_used:$swap_total:$swap_used" );
my $ERR = RRDs::error();
warning("ERROR while updating mem.rrd: $ERR") if $ERR;
RRDs::update( 'mem2.rrd', "N:$mem_shared:$mem_buffers:$mem_cached" );
$ERR = RRDs::error();
warning("ERROR while updating mem2.rrd: $ERR") if $ERR;