root / plugins / other / lpar_cpu @ 08b6b881
Historique | Voir | Annoter | Télécharger (1,82 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
# |
| 3 |
# Plugin to monitor physical cpu usage in an IBM POWER P5 / OpenPower LPAR |
| 4 |
# |
| 5 |
# Usage: Place in /etc/munin/plugins (or make a symlink to it there) |
| 6 |
# |
| 7 |
# Parameters understood: |
| 8 |
# |
| 9 |
# config |
| 10 |
# autoconf |
| 11 |
# |
| 12 |
# This should be run as root, so drop a file with something like this in |
| 13 |
# /etc/munin/plugin-conf.d/lpar_cpu: |
| 14 |
# [lpar_cpu] |
| 15 |
# user root |
| 16 |
# |
| 17 |
# Great thanks to Nigel Griffith of IBM for the magic to get these values |
| 18 |
# |
| 19 |
# Author: Ingvar Hagelund <ingvar(at)linpro.no> |
| 20 |
# |
| 21 |
# Licence: GNU General Public Licence v2.0, |
| 22 |
# see http://www.gnu.org/copyleft/gpl.html |
| 23 |
|
| 24 |
use strict; |
| 25 |
|
| 26 |
my $stats="/proc/ppc64/lparcfg"; |
| 27 |
my $cpuinfo="/proc/cpuinfo"; |
| 28 |
my $seconds=2; |
| 29 |
my $counter=""; |
| 30 |
my $after=""; |
| 31 |
my $timebase=""; |
| 32 |
|
| 33 |
sub readstats {
|
| 34 |
my $stats=shift; |
| 35 |
my $purr; |
| 36 |
|
| 37 |
open (STATS,"$stats") or die "Unable to read $stats, $!"; |
| 38 |
while (<STATS>) {
|
| 39 |
if ( /^purr\=(\d+)$/ ) { $purr = $1; }
|
| 40 |
} |
| 41 |
close STATS; |
| 42 |
return $purr; |
| 43 |
} |
| 44 |
|
| 45 |
sub error {
|
| 46 |
print "something horrible happened\n"; |
| 47 |
exit 2; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
################ |
| 52 |
# |
| 53 |
# Main |
| 54 |
# |
| 55 |
# |
| 56 |
|
| 57 |
if ( defined $ARGV[0] ) {
|
| 58 |
|
| 59 |
if ( $ARGV[0] eq 'autoconf' ) {
|
| 60 |
if ( -e $stats && -e $cpuinfo ) {
|
| 61 |
print "yes\n"; |
| 62 |
exit 0; |
| 63 |
} |
| 64 |
else {
|
| 65 |
print "no\n"; |
| 66 |
exit 1; |
| 67 |
} |
| 68 |
} |
| 69 |
elsif ( $ARGV[0] eq 'config' ) {
|
| 70 |
print "graph_title LPAR physical CPU usage\n"; |
| 71 |
print "graph_args --base 1000\n"; |
| 72 |
print "graph_vlabel percent\n"; |
| 73 |
print "graph_category system\n"; |
| 74 |
print "cpu.label cpu\n"; |
| 75 |
print "cpu.type DERIVE\n"; |
| 76 |
print "cpu.min 0\n"; |
| 77 |
exit 0; |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
$counter=readstats($stats); |
| 82 |
|
| 83 |
open (CPUINFO,$cpuinfo) or die "Unable to read $cpuinfo, $!"; |
| 84 |
while (<CPUINFO>) {
|
| 85 |
if (/^timebase\s+\:\s+(\d+)/) { $timebase=$1; }
|
| 86 |
} |
| 87 |
close CPUINFO; |
| 88 |
|
| 89 |
error() if $cpuinfo eq ""; |
| 90 |
error() if $counter eq ""; |
| 91 |
error() if $timebase eq ""; |
| 92 |
|
| 93 |
my $val=100*$counter/$timebase; |
| 94 |
$val =~ s/(\d+)\..+/$1/; |
| 95 |
print "cpu.value " . $val . "\n"; |
| 96 |
exit 0; |
| 97 |
|
