2
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/system/memory_by_process
2012-04-04 01:55:07 -07:00

67 lines
1.6 KiB
Bash
Executable file

#!/bin/sh
#
# Copyright (C) 2006 Holger Levsen
#
# 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; version 2 dated June,
# 1991.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
if [ "$1" = "config" ]; then
echo "graph_title VM by Process"
echo 'graph_args --base 1024k'
echo 'graph_vlabel VM size'
echo 'graph_category system'
echo "graph_info Shows contribution of each process to VM size"
ps auxww | perl '
$junk = <>;
while (<>)
{
@a = split;
$proc = $a[10];
$proc =~ s|.*/||;
$proc =~ s/:.*//;
$proc =~ tr/[]//d;
$proc =~ tr/A-Za-z0-9/_/c;
$vsz = $a[4];
$total{$proc} += $vsz;
}
my $stack = 0;
sub draw() { return $stack++ ? "STACK" : "AREA" }
print map
{
"$_.label $_\n" .
"$_.min 0\n" .
"$_.draw " . draw() . "\n" .
"$_.cdef $_,1024,*\n"
}
sort keys %total;
'
exit 0
else
ps auxww | perl -e '
$junk = <>;
while (<>)
{
@a = split;
$proc = $a[10];
$proc =~ s|.*/||;
$proc =~ s/:.*//;
$proc =~ tr/[]//d;
$proc =~ tr/A-Za-z0-9/_/c;
$vsz = $a[4];
$total{$proc} += $vsz;
}
print map {"$_.value $total{$_}\n"} sort keys %total'
fi