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

71 lines
1.8 KiB
Text
Raw Normal View History

2010-06-08 16:54:20 +02:00
#!/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 -e '
2010-06-08 16:54:20 +02:00
$junk = <>;
while (<>)
{
@a = split;
$proc = $a[10];
$label = $proc;
$proc =~ s/ .*//;
if($proc =~ /^\[/) { $proc =~ s|/.*||; } else { $proc =~ s|.*/||; }
2010-06-08 16:54:20 +02:00
$proc =~ s/:.*//;
$proc =~ tr/[]//d;
$proc =~ tr/A-Za-z0-9/_/c;
$vsz = $a[4];
$total{$proc} += $vsz;
$labels{$proc} = $label;
2010-06-08 16:54:20 +02:00
}
my $stack = 0;
sub draw() { return $stack++ ? "STACK" : "AREA" }
print map
{
"$_.label " . $labels{$_} . "\n" .
2010-06-08 16:54:20 +02:00
"$_.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];
if($proc =~ /^\[/) { $proc =~ s|/.*||; } else { $proc =~ s|.*/||; }
2010-06-08 16:54:20 +02:00
$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