#!/usr/bin/perl -w # # mrtg-load # John Simpson 2007-08-28 # # reads the system's 5- and 15-minute load averages from the kernel # prints it out in a format suitable for MRTG # ############################################################################### # # Copyright (C) 2007 John Simpson. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 3, as # published by the Free Software Foundation. # # 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, see . # ############################################################################### require 5.003 ; use strict ; ############################################################################### sub uptime() { open ( I , " ; close I ; $line =~ m|^(\d+)| ; my $s = $1 ; my $d = int ( $s / 86400 ) ; $s %= 86400 ; my $h = int ( $s / 3600 ) ; $s %= 3600 ; my $m = int ( $s / 60 ) ; $s %= 60 ; if ( $d > 0 ) { return sprintf ( "%d days %2d:%02d:%02d" , $d , $h , $m , $s ) ; } if ( $h > 0 ) { return sprintf ( "%d:%02d:%02d" , $h , $m , $s ) ; } if ( $m > 0 ) { return sprintf ( "%d:%02d" , $m , $s ) ; } return "$s seconds" ; } ############################################################################### ############################################################################### ############################################################################### my $in = 0 ; my $out = 0 ; my $uptime = uptime() ; my $system = `hostname -f` ; open ( I , " ; close I ; $line =~ m|^\S+\s+(\S+)\s+(\S+)| ; my ( $la , $lb ) = ( $1 , $2 ) ; $la *= 100 ; $lb *= 100 ; print "$la\n$lb\n$uptime\n$system" ;