Schrift
[thread]6639[/thread]

Script zur Auswertung von Servertransfers: Script zur Auswertung von Servertransfer



<< >> 8 Einträge, 1 Seite
Gast Gast
 2005-01-19 16:26
#50876 #50876
Hallo!
ich habe folgendes Problem - und zwar versuche ich für meine Abteilung ein Script zu schreiben, das die Transfers der einzelnen Serververzeichnisse (sowohl on- als auch offline) so aufteilt, dass die Unterverzeichnisse addiert und vom übergeordneten Verzeichnis subtrahiert werden.
Als Quelle dient ein generiertes Textfile, das ausgelesen wird.
Unten ist mein bisheriger Quelletext (mit vielen Ausgaben zur Überprüfung ;) ) wo ich bisher bei der Ausführung nur recht unrealistische Zahlenwerte bekomme.
Vielleicht kann mir jemand einen entscheidenden Tipp geben?
Danke...
_
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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/perl

use strict;

#############################################

# Skript, dass den Output von KSc-Tool für Excel-Tabelle aufbereitet

# V0.5 Klaus Kirchner & Andreas Keller

# 17.01.2005

####################################################

my @foldersets;
my $index=0;
my $maxdepth;

sub getstuff
{ #Füllt das Array mit Verzeichnisdaten

my ($verzeichnis,$online,$offline)=@_;
my $deep;
 
  $foldersets[0][$index]=$verzeichnis; #bekommt die Verzeichnisnamen zugewiesen
  $foldersets[1][$index]=$online; #Die Transferraten online
  $foldersets[2][$index]=$offline; #die Transferraten offline
  $deep=&checkdepth;
  $foldersets[3][$index]=0; #ob diese Verzeichnisinfos schon verarbeitet wurden
  $foldersets[4][$index]=$deep; #die Verzeichnistiefe
  $index++;

}


sub checkdepth
{ #Ermittelt die Verzeichnistiefe
my @folder;
my $help;
@folder = split("/",$foldersets[0][$index]);

$help=$#folder;
$help;

}


sub readfile
{ #Liest Daten aus dem Textfile
my $counter=0;
my @line;
my $zahl;
my $hoch=0;


open (FILE, "klaus.txt");

  while (<FILE>)
  {
    chomp;
    if ($counter < 1)
    {}
    else
    {
       @line = split;
       #print "$line[0]\t$line[1] $line[2]\t$line[3]\t$line[4] $line[5]\t$line[6]\n";
      &getstuff($line[0],$line[2],$line[5]);
    }
    $counter++;
  }

}



my $i=0;
my $j=20;
my $h=0;
my $k=0;
my $x=0;
my $onl=0;
my $offl=0;

my $heap;
my $stack;
my $word;
my $name;
my $zwi;



&readfile;

#for($i=0;$i<=$index;$i++)
#{
 # print "$foldersets[0][$i] \t$foldersets[1][$i]#\t$foldersets[2][$i]\t$foldersets[3][$i]  \n";
 
#}

#print "\n\n\n\nIIIIIIIIIIIIIIIIIIIIIIIIIIII\nIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII#\n\n\n\n";


$i=0;
for($i=0;$i<=$index;$i++)
{


    for($j=0;$j<=$index;$j++)
    {
    if($foldersets[0][$i] eq $foldersets[0][$j])
    {
       }
       else
    {  
  $word = $foldersets[0][$i];
  $word =~ s <(.*/)(.*)><\1>;
  $word =~ s </$><>;
 
  $name = $foldersets[0][$j];
  $name =~ s <(.*/)(.*)><\1>;
  $name =~ s </$><>;
           
     
       if($foldersets[4][$j]<$foldersets[4][$j-1])
       {
         $foldersets[1][$i]-=$onl;
         $foldersets[2][$i]-=$offl;
         $onl=0;
         $offl=0;
       }
     
 
   
   
       if($word eq $name)
         {
            #print "$word\n";
           
            #print "$foldersets[0][$i]\t$foldersets[1][$i]\t$foldersets[2][$i]\n";
           
            if($foldersets[3][$i]==0)
            {            
              $onl+=$foldersets[1][$i];
              $offl+=$foldersets[2][$i];
              $foldersets[3][$i]=1;
            }
           
            $heap=$word;
                       
            $j=$index; $k=0;
           #print "$foldersets[0][$i]\t$foldersets[1][$i]\t$foldersets[2][$i]\n";
           print "\t$foldersets[0][$i]\t\t\t$onl\t$offl\n\n";
                                   
         }
       }
     
 
 
 
 
  #if($heap eq $foldersets[0][$i])
    #{
    # $foldersets[1][$i]-=$onl;
    # $foldersets[2][$j]-=$offl; print "AUS I!!! $foldersets[0][$i]\t$foldersets[1][$i]\t$foldersets[2][$i]\n";
    #  next;
    #}
    #elsif ($heap eq $foldersets[0][$j])
    #{
    #  $foldersets[1][$j]-=$onl;
    #  $foldersets[2][$j]-=$offl; print "AUS J!!! $foldersets[0][$j]\t$foldersets[1][$j]\t$foldersets[2][$j]\n";
    #  next;
    #}
 

}




}
#for($i=0;$i<=$index;$i++)
#{
 #print "$foldersets[0][$i] \t$foldersets[1][$i]\t$foldersets[2][$i]\t$foldersets[3][$i]  \n";
 
#}


Edit: renee: [code]-Tags spendiert\n\n

<!--EDIT|renee|1106145003-->
renee
 2005-01-19 16:31
#50877 #50877
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Vielleicht zeigst Du mal, wie so eine Ausgangsdatei aussieht...
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/
Andi-Bar
 2005-01-19 16:44
#50878 #50878
User since
2005-01-19
3 Artikel
BenutzerIn
[default_avatar]
Gerne...
ist jetzt aber sehr lang - ich poste nur ein zehntel der Ausgabe:
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
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
106
107
108
109
110
111
112
113
        /cray/cray                      125604.35       596912.06

       /cray/dmf_backups                       126686.07       598606.89

       /cray/dmfsave                   126686.07       598606.89

       /cray/dsmc                      126723.67       598623.03

       /cray/eas                       134277.59       803502.31

       /cray/metric                    134560.6        803512.26

       /cray/no_dmf/eas                        -133973.09      -803170.27

       /cray/no_dmf/gapc                       280094.18       803170.27

       /cray/otg                       280117.72       806408.92

       /cray/vds0001                   280117.84       806408.92

       /cray/vds0310                   309833.56       864078.78

       /cray/vds4316                   309833.59       864631.89

       /cray/wvteco                    309833.65       864631.89

       /cray/cra                       911599.75       18861313.37

       /cray/gapc                      1049792.99      21249060.26

       /cray/mef                       1070055.47      21354829.81

       /cray/mep                       1077867.34      22236853.21

       /cray/vds                       1137536.61      23696736.7

       /cray/vds0000                   1137536.73      23697901.03

       /cray/vds0408                   1137559.61      23736291.9

       /cray/vds0410                   1137559.83      23736472.98

       /cray/vds0411                   1137580.55      23738617.53

       /cray/vds0421                   1137598.68      23746709.42

       /cray/vds3000                   1137732.65      23750869.33

       /cray/vds3082                   1137732.71      23751142.94

       /cray/vds3100                   1138261.59      23778577.93

       /cray/vds3110                   1138606.29      23822373.43

       /cray/vds3200                   1141345.48      24055557.14

       /cray/vds3210                   1142214.34      24147442.32

       /cray/vds3220                   1142278 24227026.57

       /cray/vds3300                   1144699.68      24823781.95

       /cray/vds3301                   1144902.65      24991650.85

       /cray/vds3305                   1150864.51      25135525.51

       /cray/vds3307                   1150996.57      25173611.21

       /cray/vds3330                   1151056.95      25204973.25

       /cray/vds3350                   1153442.24      25462744.25

       /cray/vds3370                   1165253.96      25917959.2

       /cray/vds3500                   1165491.91      25938794.06

       /cray/vds3700                   1197747.3       26157642.63

       /cray/vds4300                   1197928.43      26186863.13

       /cray/vds4335                   1198101.98      26224170.99

       /cray/vds4400                   1220793.26      27144427.84

       /cray/vds4401                   1258413.72      27313013.09

       /cray/vdsext                    1263507.16      27418164.56

       /cray/RESTORE                   1263507.19      27418164.56

       /cray/TT_DB                     1263508.57      27418164.56

       /cray/Use                       1263508.6       27418164.56

       /cray/ae                        1263508.63      27418164.56

       /cray/cccsup                    1263508.82      27418164.56

       /cray/cccsys                    1263527.29      27418314.81

       /cray/gast                      1263528.23      27418318.09

       /cray/mogefa                    1263528.29      27418318.09

       /cray/operator                  1263528.32      27418318.09

       /cray/radioss                   1263528.32      27418318.09

       /cray/sadmin                    1263714.86      27423984.85

       /cray/tmp                       1263714.86      27423984.85

       /cray/nodmf_gapc                        1263719.24      27425266.11
\n\n

<!--EDIT|renee|1106146204-->
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/
Andi-Bar
 2005-01-20 14:07
#50880 #50880
User since
2005-01-19
3 Artikel
BenutzerIn
[default_avatar]
Funktioniert leider auch nicht... :(.
Das komplette Textfile darf ich aufgrund des Datenschutzes nicht zeigen.
Ich glaube ich les den Mist künftig doch mit Hand aus :(...
Ich schmeiss die Sache - Danke für die Hilfsbereitschaft.
renee
 2005-01-20 14:23
#50881 #50881
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Was funktioniert nicht??

Wenn ich das Programm laufen lasse mit dem oben beschriebenen file, bekomme ich folgende Ausgabe:
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
/cray/RESTORE online= 1263507.19 offlines= 27418164.56
/cray/TT_DB online= 1263508.57 offlines= 27418164.56
/cray/Use online= 1263508.6 offlines= 27418164.56
/cray/ae online= 1263508.63 offlines= 27418164.56
/cray/cccsup online= 1263508.82 offlines= 27418164.56
/cray/cccsys online= 1263527.29 offlines= 27418314.81
/cray/gast online= 1263528.23 offlines= 27418318.09
/cray/mogefa online= 1263528.29 offlines= 27418318.09
/cray/operator online= 1263528.32 offlines= 27418318.09
/cray/radioss online= 1263528.32 offlines= 27418318.09
/cray/sadmin online= 1263714.86 offlines= 27423984.85
/cray/tmp online= 1263714.86 offlines= 27423984.85
/cray/vds3100 online= 1138261.59 offlines= 23778577.93
/cray/vds3110 online= 1138606.29 offlines= 23822373.43
/cray/vds3200 online= 1141345.48 offlines= 24055557.14
/cray/vds3210 online= 1142214.34 offlines= 24147442.32
/cray/vds3220 online= 1142278 offlines= 24227026.57
/cray/vds3300 online= 1144699.68 offlines= 24823781.95
/cray/vds3301 online= 1144902.65 offlines= 24991650.85
/cray/vds3305 online= 1150864.51 offlines= 25135525.51
/cray/vds3307 online= 1150996.57 offlines= 25173611.21
/cray/vds3330 online= 1151056.95 offlines= 25204973.25
/cray/vds3350 online= 1153442.24 offlines= 25462744.25
/cray/vds3370 online= 1165253.96 offlines= 25917959.2
/cray/vds3500 online= 1165491.91 offlines= 25938794.06
/cray/vds3700 online= 1197747.3 offlines= 26157642.63
/cray/vds4300 online= 1197928.43 offlines= 26186863.13
/cray/vds4335 online= 1198101.98 offlines= 26224170.99
/cray/vds4400 online= 1220793.26 offlines= 27144427.84
/cray/vds4401 online= 1258413.72 offlines= 27313013.09
/cray/vdsext online= 1263507.16 offlines= 27418164.56
/cray online= 37428518 offlines= 812154679.58
/renee/tmp online= 1263714.86 offlines= 27423984.85
/renee/vds3350 online= 1153442.24 offlines= 25462744.25
/renee online= 2417157.1 offlines= 52886729.1
Gesamt: Online: 39845675.1 Offline: 865041408.68

und das passt doch...
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/
Andi-Bar
 2005-01-21 12:14
#50882 #50882
User since
2005-01-19
3 Artikel
BenutzerIn
[default_avatar]
Ja das File oben ist mein Output... :(.
Das Orginal darf ich leider hier nicht posten (sind ips drinnen und so...) aber ich habe jetzt einen anderen (etwas umständlichen) weg gefunden, meine Informationen rauszufiltern... Danke für die Mühe.
MfG
renee
 2005-01-21 15:35
#50883 #50883
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Naja, Du hättest ja Dummy-Werte einsetzen können... z.B. "falsche" IPs, nicht existierende Ordnernamen...
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/
<< >> 8 Einträge, 1 Seite



View all threads created 2005-01-19 16:26.