Graphs Aenderung die ich gestern vergessen hatte

Nettraffic monitor Skripte geloescht
makegraphs bei Linequaltity auf 5 Ping und Gateway geaendert


git-svn-id: http://svn.ipfire.org/svn/ipfire/trunk@634 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8
This commit is contained in:
maniacikarus
2007-06-17 09:02:50 +00:00
parent 18322edf27
commit cce90b0b48
7 changed files with 24 additions and 479 deletions

View File

@@ -27,6 +27,8 @@ my %mbmon_settings = ();
&General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings);
my %mbmon_values = ();
&General::readhash("/var/log/mbmon-values", \%mbmon_values);
my $key;
my $value;
my @args = ();
@@ -324,6 +326,7 @@ sub updatelqgraph {
}
sub updatehddgraph {
my $disk = $_[0];
my $period = $_[1];
@@ -348,15 +351,15 @@ sub updatetempgraph
{
my $type = "temp";
my $period = $_[0];
@args = ("$graphs/mbmon-$type-$period.png", "--start", "-1$period", "-aPNG", "-i", "-z",
@args = ("$graphs/mbmon-$type-$period.png",
"--start", "-1$period", "-aPNG", "-i", "-z",
"--alt-y-grid", "-w 600", "-h 100", "--alt-autoscale",
"--color", "SHADEA".$color{"color19"},
"--color", "SHADEB".$color{"color19"},
"--color", "BACK".$color{"color21"},
"-t $tr{'mbmon temp'} ($tr{'graph per'} $tr{$period})" );
$count = 10;
"-t $tr{'mbmon temp'} ($tr{'graph per'} $tr{$period})",);
foreach $key ( sort(keys %mbmon_values) )
{
if ( (index($key, $type) != -1) && ($mbmon_settings{'LINE-'.$key} eq 'on') )
@@ -365,23 +368,17 @@ sub updatetempgraph
{
$mbmon_settings{'LABEL-'.$key} = $key;
}
push(@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
push(@args, "LINE2:$key$color{$count}:$mbmon_settings{'LABEL-'.$key} $tr{'mbmon temp in'} ?C");
push(@args, "GPRINT:$key:MAX:$tr{'maximal'}\\:%5.1lf ?C");
push(@args, "GPRINT:$key:AVERAGE:$tr{'average'}\\:%5.1lf ?C");
push(@args, "GPRINT:$key:LAST:$tr{'current'}\\:%5.1lf ?C\\j");
$count++;
}
push (@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
push (@args, "LINE2:".$key.$color{'color11'}.":$mbmon_settings{'LABEL-'.$key} $tr{'mbmon temp in'} C");
push (@args, "GPRINT:$key:MAX:$tr{'maximal'}\\:%5.1lf C");
push (@args, "GPRINT:$key:AVERAGE:$tr{'average'}\\:%5.1lf C");
push (@args, "GPRINT:$key:LAST:$tr{'current'}\\:%5.1lf C\\j");
}
}
if ( $count > 1 )
{
RRDs::graph ( @args );
RRDs::graph ( @args );
$ERROR = RRDs::error;
print("Error in RRD::graph for temp: $ERROR\n")if $ERROR;
}
}
sub updatefangraph
@@ -396,7 +393,6 @@ sub updatefangraph
"--color", "BACK".$color{"color21"},
"-t $tr{'mbmon temp'} ($tr{'graph per'} $tr{$period})" );
$count = 10;
foreach $key ( sort(keys %mbmon_values) )
{
if ( (index($key, $type) != -1) && ($mbmon_settings{'LINE-'.$key} eq 'on') )
@@ -407,21 +403,15 @@ sub updatefangraph
}
push(@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
push(@args, "LINE2:$key$color{$count}:$mbmon_settings{'LABEL-'.$key} $tr{'mbmon fan in'} rpm");
push(@args, "LINE2:".$key.$color{'color11'}.":$mbmon_settings{'LABEL-'.$key} $tr{'mbmon fan in'} rpm");
push(@args, "GPRINT:$key:MAX:$tr{'maximal'}\\:%5.0lf rpm");
push(@args, "GPRINT:$key:AVERAGE:$tr{'average'}\\:%5.0lf rpm");
push(@args, "GPRINT:$key:LAST:$tr{'current'}\\:%5.0lf rpm\\j");
$count++;
}
}
if ( $count > 1 )
{
RRDs::graph ( @args );
$ERROR = RRDs::error;
print("Error in RRD::graph for temp: $ERROR\n")if $ERROR;
}
}
sub updatevoltgraph
@@ -436,7 +426,6 @@ sub updatevoltgraph
"--color", "BACK".$color{"color21"},
"-t $tr{'mbmon temp'} ($tr{'graph per'} $tr{$period})" );
$count = 10;
foreach $key ( sort(keys %mbmon_values) )
{
my $v = substr($key,0,1);
@@ -448,19 +437,14 @@ sub updatevoltgraph
}
push(@args, "DEF:$key=$rrdlog/mbmon.rrd:$key:AVERAGE");
push(@args, "LINE2:$key$color{$count}:$mbmon_settings{'LABEL-'.$key} V");
push(@args, "LINE2:".$key.$color{'color11'}.":$mbmon_settings{'LABEL-'.$key} V");
push(@args, "GPRINT:$key:MAX:$tr{'maximal'}\\:%5.2lf V");
push(@args, "GPRINT:$key:AVERAGE:$tr{'average'}\\:%5.2lf V");
push(@args, "GPRINT:$key:LAST:$tr{'current'}\\:%5.2lf V\\j");
$count++;
}
}
if ( $count > 1 )
{
RRDs::graph ( @args );
$ERROR = RRDs::error;
print("Error in RRD::graph for temp: $ERROR\n")if $ERROR;
}
}

View File

@@ -56,6 +56,3 @@ HOME=/
# Reset Dialup Statistics
bootrun 0 0 1 * * /usr/local/bin/dialctrl.pl reset
# run traffic monitoring every 5 minutes
*/5 * * * * /usr/local/bin/monitorTraff > /dev/null

View File

@@ -79,7 +79,7 @@ if ( echo $0 | /bin/grep -q 'dhcpcd.exe' ); then
/usr/local/bin/setportfw
/usr/local/bin/setxtaccess
/usr/local/bin/setddns.pl -f
/usr/local/bin/restartsnort red
/usr/local/bin/snortctrl restart
sleep $VPN_DELAYED_START && /usr/local/bin/ipsecctrl S &
/bin/rm -f /var/lock/red.lock
logger -p local0.info -t red[$$] "unlocking from $$"
@@ -100,7 +100,7 @@ if [ -e "/var/ipfire/red/active" ]; then
/etc/rc.d/init.d/firewall reload
/usr/local/bin/setfilters
/usr/local/bin/outgoingfwctrl
/usr/local/bin/restartsnort red
/usr/local/bin/snortctrl restart
/usr/local/bin/qosctrl start
/usr/local/bin/setportfw
/usr/local/bin/setxtaccess

View File

@@ -7,7 +7,7 @@ PROGS = iowrap
SUID_PROGS = setdmzholes setportfw setfilters setxtaccess \
squidctrl restartssh ipfirereboot setaliases \
ipsecctrl timectrl dhcpctrl snortctrl \
monitorTraff restartapplejuice rebuildhosts \
restartapplejuice rebuildhosts \
restartsyslogd logwatch openvpnctrl outgoingfwctrl \
restartwireless getipstat qosctrl launch-ether-wake \
redctrl extrahdctrl sambactrl upnpctrl tripwirectrl \

View File

@@ -1,70 +0,0 @@
/* Addon helper program - monitorTraff
*
* This program is distributed under the terms of the GNU General Public
* Licence. See the file COPYING for details.
*
* Copyright (c) Achim Weber 2 November 2006
*
* Wrapper for Perl Monitoring script
*
* $Id: monitorTraff.c,v 1.4 2006/11/15 17:53:43 dotzball Exp $
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "setuid.h"
/* define parameters */
#define PARA_TEST "--testEmail"
#define PARA_WARN "--warnEmail"
#define PARA_FORCE "--force"
struct keyvalue *kv = NULL;
void usage()
{
fprintf (stderr, "Usage:\n");
fprintf (stderr, "\tmonitorTraff [PARAMETER]\n");
fprintf (stderr, "\t\tWhen called without parameter, monitorTraff calculates the traffic.\n");
fprintf (stderr, "\t\tPARAMETER:\n");
fprintf (stderr, "\t\t\t--testEmail : Send a test email\n");
fprintf (stderr, "\t\t\t--warnEmail : Send a warn email\n");
fprintf (stderr, "\t\t\t--force : Force re-calculation\n");
}
int main(int argc, char *argv[])
{
char buffer[STRING_SIZE];
if (!(initsetuid()))
return 1;
// What should we do?
if (argc==1)
{
// calc traffic
safe_system("/usr/local/bin/monitorTraffic.pl");
}
else if (argc==2
&& (strcmp(argv[1], PARA_TEST)==0
|| strcmp(argv[1], PARA_WARN)==0
|| strcmp(argv[1], PARA_FORCE)==0) )
{
// send (test|warn) Email or force re-calc
memset(buffer, 0, STRING_SIZE);
if ( snprintf(buffer, STRING_SIZE - 1, "/usr/local/bin/monitorTraffic.pl %s", argv[1]) >= STRING_SIZE )
{
fprintf(stderr, "Command too long\n");
exit(1);
}
safe_system(buffer);
}
else
{
usage();
}
return 0;
}

View File

@@ -376,8 +376,9 @@ sub updatelq {
my $roundtrip=0;
my $test=0;
# LQ_GATEWAY is the ip of your isp's public ip facing you
my $LQ_GATEWAY=`netstat -rn | grep ^0.0.0.0 | awk '{print \$2}'`;
my $NUMPINGS=10;
my $LQ_GATEWAY=`cat /var/ipfire/red/remote-ipaddress`;
chomp($LQ_GATEWAY);
my $NUMPINGS=5;
my $pingoutput = `ping -c $NUMPINGS -q $LQ_GATEWAY`;
chomp;
my @temp = split (/\/|\%|\s/, $pingoutput);

View File

@@ -1,367 +0,0 @@
#!/usr/bin/perl
#
# This code is distributed under the terms of the GPL
#
# (c) Achim Weber 2006
#
# $Id: monitorTraffic.pl,v 1.14 2006/12/15 14:43:57 dotzball Exp $
#
#
use strict;
# enable only the following on debugging purpose
use warnings;
require '/var/ipcop/general-functions.pl';
require "${General::swroot}/lang.pl";
require "${General::swroot}/net-traffic/net-traffic-lib.pl";
require "${General::swroot}/net-traffic/net-traffic-admin.pl";
my @dummy = (${Traffic::red_in},${Traffic::red_out});
undef(@dummy);
# Debug level:
# 0 - send email (if enabled), no print
# 1 - send email (if enabled), print
# 2 - only print
my $debugLevel = 0;
# Debug
my %log = ();
$log{'CALC_VOLUME_TOTAL'} = 0;
$log{'CALC_VOLUME_IN'} = 0;
$log{'CALC_VOLUME_OUT'} = 0;
$log{'CALC_WEEK_TOTAL'} = 0;
$log{'CALC_WEEK_IN'} = 0;
$log{'CALC_WEEK_OUT'} = 0;
$log{'CALC_LAST_RUN'} = 0;
$log{'CALC_PERCENT'} = 0;
$log{'WARNMAIL_SEND'} = 'no';
# current time == endtime
my $currentTime = time;
# on force we don't load the log data
unless(defined($ARGV[0]) && $ARGV[0] eq '--force') {
&General::readhash($NETTRAFF::logfile, \%log);
}
# Only send email?
if(defined($ARGV[0]) && ($ARGV[0] eq '--testEmail' || $ARGV[0] eq '--warnEmail'))
{
print "Send testmail\n" if($debugLevel > 0);
# send (test|warn) email
my $return = &sendEmail($ARGV[0]);
print "$return\n";
exit 0;
}
# should we recalculate?
# calc seconds for one interval
my $intervalTime = $NETTRAFF::settings{'CALC_INTERVAL'} * 60;
# next time, we have to calculate
my $nextRunTime = $log{'CALC_LAST_RUN'} + $intervalTime;
if ($debugLevel > 0)
{
my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($log{'CALC_LAST_RUN'});
my $lastRun = sprintf("%04d-%02d-%02d, %02d:%02d", 1900+$year, $mon+1, $mday, $hour, $min);
print "last run: $lastRun\n";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($nextRunTime);
my $nextRun = sprintf("%04d-%02d-%02d, %02d:%02d", 1900+$year, $mon+1, $mday, $hour, $min);
print "next run: $nextRun\n";
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($currentTime);
my $current = sprintf("%04d-%02d-%02d, %02d:%02d", 1900+$year, $mon+1, $mday, $hour, $min);
print "current time: $current\n";
}
# use a little time buffer in case the last run started some seconds earlier
if($currentTime < ($nextRunTime - 60) )
{
# nothing to do
if ($debugLevel > 0)
{
my $infoMsg = "Net-Traffic: nothing to do, do next calculation later.";
print "$infoMsg\n";
&General::log($infoMsg);
}
exit 0;
}
elsif($debugLevel > 0)
{
my $infoMsg = "Net-Traffic: Calc traffic now.";
print "$infoMsg\n";
&General::log($infoMsg);
}
####
# Calculate Traffic
#
$log{'CALC_LAST_RUN'} = $currentTime;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($currentTime);
#####################
# this month traffic
###
my $startDay = '1';
my $startMonth = $mon + 1;
my $startYear = $year + 1900;
if($NETTRAFF::settings{'MONTHLY_VOLUME_ON'} eq 'on')
{
$startDay = $NETTRAFF::settings{'STARTDAY'};
}
# this periode started last month
if ($mday < $startDay)
{
# when current month is january we start in last year december
if ($startMonth == 1) {
$startYear--;
$startMonth = 12;
}
else
{
$startMonth--;
}
}
$startMonth = $startMonth < 10 ? $startMonth = "0".$startMonth : $startMonth;
$startDay = $startDay < 10 ? $startDay = "0".$startDay : $startDay;
my $start = "$startYear$startMonth$startDay";
my %month = &getTrafficData($start, $currentTime);
$log{'CALC_VOLUME_TOTAL'} = $month{'TOTAL'};
$log{'CALC_VOLUME_IN'} = $month{'IN'};
$log{'CALC_VOLUME_OUT'} = $month{'OUT'};
#####################
#####################
# this week traffic
###
$startMonth = $mon;
$startYear = $year + 1900;
$startDay = $mday-($wday >0 ? $wday-1 : 6);
# borrowed from ipacsum
my @mofg = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
if ($startDay < 1) {
$startMonth--;
if ($startMonth < 0) {
$startMonth += 12;
$startYear--;
}
$startDay += $mofg[$startMonth];
}
# $mon starts at 0 but we have to start at 1
$startMonth++;
$startMonth = $startMonth < 10 ? $startMonth = "0".$startMonth : $startMonth;
$startDay = $startDay < 10 ? $startDay = "0".$startDay : $startDay;
$start = "$startYear$startMonth$startDay";
my %week = &getTrafficData($start, $currentTime);
$log{'CALC_WEEK_TOTAL'} = $week{'TOTAL'};
$log{'CALC_WEEK_IN'} = $week{'IN'};
$log{'CALC_WEEK_OUT'} = $week{'OUT'};
####################
my $infoMsg = "Reached: $log{'CALC_VOLUME_TOTAL'} MB\n";
$infoMsg .= "start: $start";
print "$infoMsg\n" if ($debugLevel > 0);
# monthly traffic volume?
if ($NETTRAFF::settings{'MONTHLY_VOLUME_ON'} eq 'on')
{
$log{'CALC_PERCENT'} = sprintf("%d", ($log{'CALC_VOLUME_TOTAL'} / $NETTRAFF::settings{'MONTHLY_VOLUME'} * 100));
my $infoMsg = "Used (\%): $log{'CALC_PERCENT'} \% - Max.: $NETTRAFF::settings{'MONTHLY_VOLUME'} MB";
print "$infoMsg\n" if ($debugLevel > 0);
if($NETTRAFF::settings{'WARN_ON'} eq 'on'
&& $log{'CALC_PERCENT'} >= $NETTRAFF::settings{'WARN'})
{
# warnlevel is reached
if ($debugLevel > 0)
{
my $warnMsg = "Net-Traffic warning: $infoMsg";
print "$warnMsg\n";
&General::log($warnMsg);
}
if($debugLevel < 2)
{
if($NETTRAFF::settings{'SEND_EMAIL_ON'} eq 'on'
&& $log{'WARNMAIL_SEND'} ne 'yes')
{
# send warn email
my $return = &sendEmail('--warnEmail');
if($return =~ /Email was sent successfully!/)
{
$log{'WARNMAIL_SEND'} = 'yes';
}
else {
$log{'WARNMAIL_SEND'} = 'no';
}
}
}
}
else
{
# warnlevel not reached, reset warnmail send
$log{'WARNMAIL_SEND'} = 'no';
}
}
&General::writehash($NETTRAFF::logfile, \%log);
exit 0;
sub getTrafficData
{
my $p_start = shift;
my $p_currentTime = shift;
if($debugLevel > 0)
{
print "----------------------\n";
print "start: $p_start\n";
print "current time: $p_currentTime\n";
}
#my $displayMode = "exactTimeframe";
my $displayMode = "exactEnd";
my %allDaysBytes = ();
my @allDays = &Traffic::calcTraffic(\%allDaysBytes, $p_start, $p_currentTime, $displayMode);
my %traff = ();
$traff{'IN'} = 0;
$traff{'OUT'} = 0;
$traff{'TOTAL'} = 0;
foreach my $day (@allDays)
{
if($debugLevel > 0)
{
print "day: $day\n";
print "in: $allDaysBytes{$day}{${Traffic::red_in}}\n";
print "out: $allDaysBytes{$day}{${Traffic::red_out}}\n";
}
$traff{'IN'} += $allDaysBytes{$day}{${Traffic::red_in}};
$traff{'OUT'} += $allDaysBytes{$day}{${Traffic::red_out}};
}
$traff{'TOTAL'} = $traff{'IN'} + $traff{'OUT'};
# formating
$traff{'TOTAL'} = sprintf("%.2f", ($traff{'TOTAL'}/1048576));
$traff{'IN'} = sprintf("%.2f", ($traff{'IN'}/1048576));
$traff{'OUT'} = sprintf("%.2f", ($traff{'OUT'}/1048576));
if($debugLevel > 0)
{
print "IN: $traff{'IN'}\n";
print "OUT: $traff{'OUT'}\n";
print "TOTAL: $traff{'TOTAL'}\n";
print "----------------------\n";
}
return %traff;
}
sub sendEmail
{
my $mailtyp = shift;
my $template = "";
my %ipcopSettings = ();
&General::readhash("${General::swroot}/main/settings", \%ipcopSettings);
my $host = "$ipcopSettings{'HOSTNAME'}.$ipcopSettings{'DOMAINNAME'}";
my $subject = "[Net-Traffic] $host: ";
if($mailtyp eq '--warnEmail')
{
$subject .= $Lang::tr{'subject warn'};
$template = "warn";
}
else
{
$subject .= $Lang::tr{'subject test'};
$template = "test";
}
if(-e "${General::swroot}/net-traffic/templates/$template.${Lang::language}")
{
$template .= ".${Lang::language}";
}
else
{
$template .= ".en";
}
# read template
open(FILE, "${General::swroot}/net-traffic/templates/$template");
my @temp = <FILE>;
close(FILE);
my $date_current = &NETTRAFF::getFormatedDate($currentTime);
my $date_lastrun = &NETTRAFF::getFormatedDate($log{'CALC_LAST_RUN'});
my $message = "";
foreach my $line (@temp)
{
chomp($line);
$line =~ s/__HOSTNAME__/$host/;
$line =~ s/__CALC_VOLUME_TOTAL__/$log{'CALC_VOLUME_TOTAL'}/;
$line =~ s/__CALC_PERCENT__/$log{'CALC_PERCENT'}/;
$line =~ s/__MONTHLY_VOLUME__/$NETTRAFF::settings{'MONTHLY_VOLUME'}/;
$line =~ s/__STARTDAY__/$NETTRAFF::settings{'STARTDAY'}/;
$line =~ s/__CURRENT_DATE__/$date_current/;
$line =~ s/__LAST_RUN__/$date_lastrun/;
$message .= "$line\n";
}
my $cmd = "/usr/local/bin/sendEmail_nettraffic -f $NETTRAFF::settings{'EMAIL_FROM'} ";
$cmd .= " -t $NETTRAFF::settings{'EMAIL_TO'} ";
$cmd .= " -u \"$subject\" ";
$cmd .= " -m \"$message\" ";
$cmd .= " -s $NETTRAFF::settings{'EMAIL_SERVER'} ";
if($NETTRAFF::settings{'EMAIL_USR'} ne '') {
$cmd .= " -xu $NETTRAFF::settings{'EMAIL_USR'} ";
}
if($NETTRAFF::settings{'EMAIL_PW'} ne '') {
$cmd .= " -xp $NETTRAFF::settings{'EMAIL_PW'} ";
}
my $return = `$cmd`;
return $return;
}