From 25dc57f7fa7baa5cbcd8ee7dc7c4d597c7d704f1 Mon Sep 17 00:00:00 2001 From: Ingvar Hagelund Date: Wed, 20 Jun 2007 15:58:27 +0200 Subject: [PATCH] Initial version --- plugins/other/lpar_cpu | 97 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100755 plugins/other/lpar_cpu diff --git a/plugins/other/lpar_cpu b/plugins/other/lpar_cpu new file mode 100755 index 00000000..efda4c10 --- /dev/null +++ b/plugins/other/lpar_cpu @@ -0,0 +1,97 @@ +#!/usr/bin/perl -w +# +# Plugin to monitor physical cpu usage in an IBM POWER P5 / OpenPower LPAR +# +# Usage: Place in /etc/munin/plugins (or make a symlink to it there) +# +# Parameters understood: +# +# config +# autoconf +# +# This should be run as root, so drop a file with something like this in +# /etc/munin/plugin-conf.d/lpar_cpu: +# [lpar_cpu] +# user root +# +# Great thanks to Nigel Griffith of IBM for the magic to get these values +# +# Author: Ingvar Hagelund +# +# Licence: GNU General Public Licence v2.0, +# see http://www.gnu.org/copyleft/gpl.html + +use strict; + +my $stats="/proc/ppc64/lparcfg"; +my $cpuinfo="/proc/cpuinfo"; +my $seconds=2; +my $counter=""; +my $after=""; +my $timebase=""; + +sub readstats { + my $stats=shift; + my $purr; + + open (STATS,"$stats") or die "Unable to read $stats, $!"; + while () { + if ( /^purr\=(\d+)$/ ) { $purr = $1; } + } + close STATS; + return $purr; +} + +sub error { + print "something horrible happened\n"; + exit 2; +} + + +################ +# +# Main +# +# + +if ( defined $ARGV[0] ) { + + if ( $ARGV[0] eq 'autoconf' ) { + if ( -e $stats && -e $cpuinfo ) { + print "yes\n"; + exit 0; + } + else { + print "no\n"; + exit 1; + } + } + elsif ( $ARGV[0] eq 'config' ) { + print "graph_title LPAR physical CPU usage\n"; + print "graph_args --base 1000\n"; + print "graph_vlabel percent\n"; + print "graph_category system\n"; + print "cpu.label cpu\n"; + print "cpu.type DERIVE\n"; + print "cpu.min 0\n"; + exit 0; + } +} + +$counter=readstats($stats); + +open (CPUINFO,$cpuinfo) or die "Unable to read $cpuinfo, $!"; +while () { + if (/^timebase\s+\:\s+(\d+)/) { $timebase=$1; } +} +close CPUINFO; + +error() if $cpuinfo eq ""; +error() if $counter eq ""; +error() if $timebase eq ""; + +my $val=100*$counter/$timebase; +$val =~ s/(\d+)\..+/$1/; +print "cpu.value " . $val . "\n"; +exit 0; +