X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2Fbin%2Ffreeside-torrus-srvderive;h=19dd50ea450c4b32da493fe7742f42699beea404;hb=283db3852b84e9716e308c8792cdb983e033b60c;hp=a02d23ea05cb4c2fd9462484f968a85b57f23d3c;hpb=89cd0ae97ac521827060f147528d3c99de24b38a;p=freeside.git diff --git a/FS/bin/freeside-torrus-srvderive b/FS/bin/freeside-torrus-srvderive index a02d23ea0..19dd50ea4 100644 --- a/FS/bin/freeside-torrus-srvderive +++ b/FS/bin/freeside-torrus-srvderive @@ -11,8 +11,8 @@ use FS::Record qw( qsearch str2time_sql str2time_sql_closing concat_sql ); use FS::torrus_srvderive; our $DEBUG = 2; -our $max_kids = 6; -our $search_timeout = 30*60; # 15*60 5*60; #$torrus_srvderive->last_srv_date ? 5*60 : 15*60); +our $max_kids = 12; +our $search_timeout = 60*60; #30*60; # 15*60 5*60; #$torrus_srvderive->last_srv_date ? 5*60 : 15*60); our %kids; my $user = shift or die &usage; @@ -61,7 +61,12 @@ my $sql = " my $orderlimit = " ORDER BY srv_date, srv_time LIMIT 100 -"; #50? +"; + +if ( driver_name =~ /mysql/i ) { + dbh->do('SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED'); + dbh->commit or die dbh->errstr; +} our $kids = 0; @@ -102,7 +107,7 @@ while (1) { exit unless @serviceids; #don't try to search for empty virtual ports #nonlocking select statements; rows in this table never change - if ( driver_name eq 'mysql' ) { + if ( driver_name =~ /mysql/i ) { dbh->do('SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED'); dbh->commit or die dbh->errstr; } @@ -162,7 +167,7 @@ while (1) { #warn "search timed out; reconnecting and restarting\n"; warn "search timed out\n"; dbh->clone()->do("KILL QUERY ". dbh->{"mysql_thread_id"}) - if driver_name eq 'mysql'; + if driver_name =~ /mysql/i; dbh->rollback; #or die dbh->errstr; #adminsuidsetup($user); #next SERVICEID; #MAIN; @@ -190,20 +195,27 @@ while (1) { my $sin = join(',', map dbh->quote("$_$dir"), @serviceids); + my $srv_date = time2str('%Y-%m-%d', $cur); + my $sum = " SELECT COALESCE(SUM(value),0) FROM srvexport AS other WHERE other.serviceid IN ($sin) + AND other.srv_date = '$srv_date' AND ABS( $cur - $other_date ) <= 60 "; + my $ssth = dbh->prepare($sum) or die $DBI::errstr; + $ssth->execute or die $ssth->errstr; #better recovery? + my $value = $ssth->fetchrow_arrayref->[0]; my $isql = " - INSERT INTO srvexport ( srv_date, srv_time, serviceid, value, intvl ) - VALUES ( ?, ?, ?, ($sum), ? ) + INSERT INTO srvexport (srv_date, srv_time, serviceid, value, intvl) + VALUES ( ?, ?, ?, ?, ? ) "; - my @param = ( time2str('%Y-%m-%d', $cur), #srv_date - time2str('%X', $cur), #srv_time - "$serviceid$dir", - 300, #intvl ... + my @param = ( $srv_date, + time2str('%X', $cur), #srv_time + "$serviceid$dir", #serviceid + $value, + 300, #intvl ... ); warn $isql. ' with param '. join(',',@param). "\n" if $DEBUG > 2;