[go: up one dir, main page]

Menu

[76a40f]: / load.pl  Maximize  Restore  History

Download this file

106 lines (86 with data), 2.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
#!/usr/bin/perl -w
###############################################################################
# Webmin Sysstats - load.pl
#
# Webmin Sysstats Module
# Copyright (C) 2002 by Eric Gerbier
# Bug reports to: gerbier@users.sourceforge.net
# $Id$
#
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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.
#
###############################################################################
use strict;
# to be used alone or from sysstat.pl without warning
# because require verify the path
require '../../gen-lib.pl' if ( !exists $ENV{WEBMINSTAT_TEMP} );
use RRDs;
my $info = 'uptime';
###############################################################################
sub read_load() {
my ( $load1, $load5, $load15 ) = ( 'U', 'U', 'U' );
if ( open( INFO, "$info | " ) ) {
while (<INFO>) {
s/,//g;
m/load averages?: (.*)/;
( $load1, $load5, $load15 ) = split( ' ', $1 );
}
close(INFO);
}
else {
warning("can not open $info : $!");
}
return ( $load1, $load5, $load15 );
}
###############################################################################
my %config;
read_file_cached( 'config', \%config );
my $param = 'load';
my $load_num = 1;
my @t_load = read_load();
#return unless (@t_load);
#debug( "load1 = $t_load[0]");
#debug( "load5 = $t_load[1]");
#debug( "load15 = $t_load[2]");
my %h_load = (
load1 => $t_load[0],
load5 => $t_load[1],
load15 => $t_load[2]
);
#foreach my $elem (keys %h_load) {
# debug( "$elem -> $h_load{$elem}");
#}
while ( exists( $config{ $param . $load_num } ) ) {
my @tab = split( /,/, $config{ $param . $load_num } );
my $real_load_num = $tab[0];
my $load = $tab[1];
my $load_name = $tab[2];
my $runstop = $tab[4];
#debug( "load = $load");
my $total = 'U';
if ( is_param_runstop($runstop) ) {
if ( exists( $h_load{$load} ) ) {
$total = $h_load{$load};
}
else {
debug("load : can not find $load value");
}
}
else {
debug("load $load disable");
}
debug("load $load ($load_name $real_load_num): total=$total");
my $rrdbase = $real_load_num . '.rrd';
RRDs::update( $rrdbase, "N:$total" );
my $ERR = RRDs::error();
warning("ERROR while updating $rrdbase: $ERR") if $ERR;
$load_num++;
}