#!/usr/bin/perl -w
###############################################################################
# Webmin Sysstats - irq.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;
use warnings;
no warnings 'redefine';
use RRDs;
use English qw(-no_match_vars);
use FindBin;
# to be used alone or from sysstat.pl without warning
# because require verify the path
if ( !exists $ENV{WEBMINSTAT_TEMP} ) {
use lib "$FindBin::Bin/../..";
## no critic (RequireBarewordIncludes)
require 'sysstats-aquisition-lib.pl';
## use critic
}
my $module_name;
my $info = '/proc/interrupts';
###############################################################################
sub read_irq() {
my $r_tab = read_full_file($info);
return @{$r_tab};
}
###############################################################################
my %config;
read_file_cached( 'config', \%config );
$module_name = $config{'name'};
debug( "run $module_name version " . $config{'version'} );
my %codes = action_load( \%config );
my @irq = read_irq();
if ( !@irq ) {
warning("no data from $info");
goto FIN;
}
# get number of cpu (cf irq-lib)
my $cpu_line = shift @irq;
my @cpu = split_awk($cpu_line);
my $nb_cpu = scalar @cpu;
my $pre = $config{'pre'};
my $irq_num = 1;
while ( exists $config{ $pre . $irq_num } ) {
my @tab = split /,/, $config{ $pre . $irq_num };
my $real_irq_num = $tab[0];
my $irq = $tab[1];
my $irq_name = $tab[2];
my $runstop = $tab[4];
#debug( "irq = $irq");
my $total = 'U';
if ( is_param_runstop($runstop) ) {
foreach my $elem (@irq) {
my @tab2 = split_awk($elem);
if ( $tab2[0] =~ m/^\s*${irq}:/ ) {
$total = 0;
# loop on cpu columns
foreach my $i ( 1 .. $nb_cpu ) {
$total += $tab2[$i] if ( $tab2[$i] );
}
#debug( "elem=$elem");
last;
}
}
debug("$module_name $irq ($irq_name $real_irq_num): total=$total");
# DERIVE parameters
#action_param( $irq, $total, \%codes );
}
else {
debug("aquisition for $irq stopped");
}
my $rrdbase = $real_irq_num . '.rrd';
RRDs::update( $rrdbase, "N:$total" );
my $ERR = RRDs::error();
warning("ERROR while updating $rrdbase database : $ERR") if $ERR;
$irq_num++;
}
# a label to quit
#I can not use return when executing this script standalone,
# so I had to use goto
FIN: