[prev in list] [next in list] [prev in thread] [next in thread]
List: os-sim-commits
Subject: [Os-sim-commits] os-sim/scripts/sem generate_stats.pl,NONE,1.1
From: Alberto Roman Linacero <alberto_r () users ! sourceforge ! net>
Date: 2009-04-30 10:17:04
Message-ID: E1LzTKC-0004dZ-W5 () 23jxhf1 ! ch3 ! sourceforge ! com
[Download RAW message or body]
Update of /cvsroot/os-sim/os-sim/scripts/sem
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv17726
Added Files:
generate_stats.pl
Log Message:
- new script for SEm
--- NEW FILE: generate_stats.pl ---
#!/usr/bin/perl
if(!$ARGV[0]){
print "Accepts folder with *log files\n";
exit;
}
$debug = 1; # 1 for debuging info
$folder = $ARGV[0];
$folder =~ s/\/$//;
$qfolder = quotemeta $folder;
$wehavedata = 0;
%stats = ();
%already = ();
open (F,"find $folder | grep \".log\$\" |");
while ($file=<F>) {
chomp($file);
my $dir = $file; $dir =~ s/$qfolder//;
my @fields = split(/\//,$dir);
if ($fields[1] =~ /(^\d+$)/) { # we dont have on a hour directory, recurse inside
my $subfolder = $folder."/".$1;
if (!$already{$subfolder}++) {
print "Recursive into $subfolder\n" if ($debug);
system ("perl /usr/share/ossim/scripts/sem/generate_stats.pl \"$subfolder\"");
}
} else {
print "Reading $file\n" if ($debug);
my $filet = $file; $filet =~ s/log$/ind/;
%rangos = ();
$lasttime = -1;
$lastdate = 4102444800;
$line = 0;
open (G,"tac '$file' |");
while (<G>) {
chomp;
#if (/ id='(\d+)' .* date='(\d+)' plugin_id='([^']+)' sensor='([^']+)' \
src_ip='([^']+)' dst_ip='([^']+)' src_port='([^']+)' dst_port='([^']+)' \
tzone='([^']+)' data='([^']+)'/) { if (/ id='(\d+)' .* date='(\d+)' \
plugin_id='([^']+)' sensor='([^']+)' src_ip='([^']+)' dst_ip='([^']+)' \
src_port='([^']+)' dst_port='([^']+)'/) { $line++; $id = $1; $fecha = $2;
my @timeData = localtime($fecha);
if ($timeData[1] != $lasttime && $fecha<$lastdate) {
$lasttime = $timeData[1];
$lastdate = $fecha;
$rangos{$fecha} = "$line:$id";
}
$stats{"plugin_id"}{$3}++;
$stats{"sensor"}{$4}++;
$stats{"src_ip"}{$5}++;
$stats{"dst_ip"}{$6}++;
$stats{"src_port"}{$7}++;
$stats{"dst_port"}{$8}++;
#$stats{"time_zone"}{$9}++;
#$stats{"data"}{$10}++;
$wehavedata++;
}
}
close G;
print "\tGenerate Index $filet\n" if ($debug);
open (S,">$filet");
foreach $date (sort {$b<=>$a} keys (%rangos)) {
print S "$date:$rangos{$date}\n";
}
print S "lines:$line\n";
close S;
}
}
close F;
# sort stats
@arr = ("plugin_id","sensor","src_ip","dst_ip","src_port","dst_port");
if ($wehavedata>0) {
print "Writing $folder/data.stats\n" if ($debug);
open(F,">$folder/data.stats");
foreach $type (@arr) {
foreach $value (sort {$stats{$type}{$b}<=>$stats{$type}{$a}} keys \
(%{$stats{$type}})) { print F $type.":".$value.":".$stats{$type}{$value}."\n";
}
}
close F;
}
print "Done.\n" if ($debug);
------------------------------------------------------------------------------
Register Now & Save for Velocity, the Web Performance & Operations
Conference from O'Reilly Media. Velocity features a full day of
expert-led, hands-on workshops and two days of sessions from industry
leaders in dedicated Performance & Operations tracks. Use code vel09scf
and Save an extra 15% before 5/3. http://p.sf.net/sfu/velocityconf
_______________________________________________
Os-sim-commits mailing list
Os-sim-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/os-sim-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic