Thread Script zur Auswertung von Servertransfers: Script zur Auswertung von Servertransfer (7 answers)
Opened by Gast at 2005-01-19 16:26

renee
 2005-01-20 11:48
#50879 #50879
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Nimm mal dieses Script:
Code: (dl )
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
#! /usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

my %hash;
my $log_file = '/path/to/file.log';
open(LOG,"<$log_file") or die $!;
while(<LOG>){
next if($_ =~ /^\s*?$/);
 $_ =~ s/^\s+//;
 my ($path,$online,$offline) = split(/\s+/,$_);
 $path =~ s/^\///; #/
 my ($key,$sub) = split(/\//,$path,2);
 $hash{$key} = insert_rec($key,$sub,$online,$offline,$hash{$key});
}
close LOG;

my ($traffic_on,$traffic_off) = calc_traffic(\%hash,'');
print "Gesamt: Online: ",$traffic_on," Offline: ",$traffic_off,"\n";

# insert_rec builds the hash recursivly.
# Parameters:
#   key of anonymous hash that has to be expanded
#   remaining path
#   online traffic
#   offline traffic
#   reference to hash
sub insert_rec{
 my ($key2,$path,$online,$offline,$hashref) = @_;
 my ($key,$sub) = split(/\//,$path,2);
 unless($sub){
   $hashref->{$key} = {online => $online, offline => $offline};
   return($hashref);
 }
 $hashref->{$key} = insert_rec($key,$sub,$online,$offline,$hashref->{$key}) if($sub);
 return ($hashref);
}# end insert_rec

# calc traffic calculates the traffic.
# Traffic of a directory includes the traffic of sub-directories
# Parameters:
#    Reference to a hash that contains the structure and the on-/offline-traffic
sub calc_traffic{
 my ($hashref,$path) = @_;
 my $onlines  = $hashref->{online};
 my $offlines = $hashref->{offline};
 foreach my $key(keys(%$hashref)){
   next unless(ref($hashref->{$key}));
   my $new_path = $path.'/'.$key;
   my ($on,$off) = calc_traffic($hashref->{$key},$new_path);
   $onlines  += $on;
   $offlines += $off;
   print $new_path," online= ",$on," offlines= ",$off,"\n";
 }
 return ($onlines,$offlines);
}# end calc_traffic
\n\n

<!--EDIT|renee|1106222558-->
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread Script zur Auswertung von Servertransfers: Script zur Auswertung von Servertransfer