hostultra

Well-Known Member
Aug 21, 2002
167
0
166
Yesterday my bandwidth screwed up for all sites
yesterdays bandwidth got multiplied by about 1000 before it got counted
eg. yesterday total bandwidth for this month was 75GB today its 50021GB!!!! and the MRTG is normal so it is a mistake (possibly by upgrading to cpanel 6 and then the auto update downgraded it back to 5.3)

I know cpanel keeps the apache log files and i know where it is
I really dont want to have to write a script to process the log files for apache and change the value of the bandwidth usage in /var/cpanel/bandwidth

Is there something i can run that will recalculate the bandwidth without me having to write my own?

--
Eric
 

hostultra

Well-Known Member
Aug 21, 2002
167
0
166
i made a script to recalculate the bandwidth :)
since other have this problem i will post it here too

must be run as root
it wont count as much traffic as cpanel did for some reason but its better then nothing

backup your /var/cpanel/bandwidth first
cpanel 6 seems to count bandwidth fine, just the first time after upgrading it doesnt work


#!/usr/bin/perl

opendir (DIR,&/var/cpanel/users&);
while ($fileName = readdir(DIR)) {
next if ($fileName !~ /\w/);
$ls[$x] = $fileName;
$x+=1;
}
closedir(DIR);

$grandtotal = &0&;

foreach $acc (@ls){
next if $acc eq &&;

open (FILE,&/var/cpanel/users/$acc&);
@lines =&FILE&;
close (FILE);

foreach $line (@lines){
$line =~ s/\n//g;
$line =~ s/\r//g;
($name,$value) = split(/\=/,$line);

if ($name ne &DNS&){
($x,$y) = split(/DNS/,$name);
if ($y ne &&){
$userdomains = &$userdomains|$value&;
}
} else {
$userdomains = &$value&;
}
}

(@domains) = split(/\|/,$userdomains);

$totalbw = &0&;
foreach $domain (@domains){
$thisdomain = &0&;
if (-e &/usr/local/apache/domlogs/$domain&){
open (FILE,&/usr/local/apache/domlogs/$domain&);
@logfile =&FILE&;
close (FILE);

foreach $logline (@logfile){
($crap,$crap,$useful) = split(/\&/,$logline);
($crap,$crap,$bytes) = split(/\ /,$useful);
if ($bytes !~ /^[0-9]*$/i){
} else {
if ($bytes & 0){
$bytes = $bytes - $bytes - $bytes;
}

if ($bytes & 0){
$bytes = &0&;
}

$thisdomain = $thisdomain + $bytes;
$totalbw = $totalbw + $bytes;
$grandtotal = $grandtotal + $bytes;
}
}

@logfile = ('','');

open (FILE,&/var/cpanel/bandwidth/$domain&);
@bwlines =&FILE&;
close (FILE);

$newfile = &&;
foreach $bwline (@bwlines){
$bwline =~ s/\n//g;
$bwline =~ s/\r//g;

($mon,$bytes) = split(/\=/,$bwline);

if ($mon eq &01.2003&){
$bwline = &01.2003=$thisdomain&;
}

$newfile = &$newfile$bwline\n&;
}

open (FILE,&&/var/cpanel/bandwidth/$domain&);
print FILE &$newfile&;
close (FILE);
$newfile = &&;
}
}

$newfile = &&;
open (FILE,&/var/cpanel/bandwidth/$acc&);
@bwlines =&FILE&;
close (FILE);

foreach $bwline (@bwlines){
$bwline =~ s/\n//g;
$bwline =~ s/\r//g;

($mon,$bytes) = split(/\=/,$bwline);

if ($mon eq &01.2003&){
$bwline = &01.2003=$totalbw&;
}

$newfile = &$newfile$bwline\n&;
}

open (FILE,&&/var/cpanel/bandwidth/$acc&);
print FILE &$newfile&;
close (FILE);
$newfile = &&;

}
 

orca

Well-Known Member
Sep 23, 2002
75
0
156
Switzerland
This just happened to me again. Even after downgrading. Now all my sites are calculated wrong. Even the NOT live ones...

Do I need to replace /var/cpanel/bandwidth with your script?

BTW, I submitted 2 trouble tickets about this and wait for a week for an answer now...
 

hostultra

Well-Known Member
Aug 21, 2002
167
0
166
no dont replace anything
just run it

/var/cpanel/bandwidth is a directory
you should backup its contents before running that script
 

orca

Well-Known Member
Sep 23, 2002
75
0
156
Switzerland
Yeah, got it. Went fine. Anyway, could that have slown down my server?
 

hostultra

Well-Known Member
Aug 21, 2002
167
0
166
weird...
mine works fine now
it was only the first time

maybe try what happened to me

downgrade cpanel 6.0 to 5.3 using the update function in WHM
and then install 6.0 again over it
 

hostultra

Well-Known Member
Aug 21, 2002
167
0
166
ahh thats whats causing it
upgrade back to 6.0

i think when you downgrade it keeps the bandwith counter from 6.0 or something

because thats what happened to me
i upgraded to 6.0 but i had my server set to auto update and STABLE releases, so it downgraded me to 5.3 automatically

6.0 works fine, but if you try to downgrade it then it causes this problem
 

hotice007

Well-Known Member
PartnerNOC
Jun 20, 2002
64
0
156
Some reason I don't have cpanel with 6.0, only WHM... any clues? Btw, the script above only give temporarly fix, it comes back about an hour later.
 

hostultra

Well-Known Member
Aug 21, 2002
167
0
166
The script i posted before was specifically written to fix the problem with Janauarys bandwidth

If your running it this month be sure to change where i have written 01.2003 to 02.2003 otherwise it will screw up
 

shaskins

Member
Dec 12, 2002
9
0
151
Problem with script

I have also encountered the problem and opened a service ticket, exact same circumstances upgrading to 6.0 and downgrading. The script will process most of the domains and then end with a Terminated response.

I would love to upgrade back to 6.0 but for some reason we lose the yourdomain.com/cpanel or yourdomain.com:2082 sporadically for undetermined amounts of time and then they start to work for no reason whatsoever.

Any ideas on the script teminating/and or the 6.0 probs.

By the way I have edited all the dates for 02.2003 to get some of my domains fixed back up.
 

hostultra

Well-Known Member
Aug 21, 2002
167
0
166
try restoring a httpd.conf from a few days ago when everything was working (unless you recently added new domains)

cpanel keeps multiple backups of httpd.conf every time it changes it
look in /usr/local/apache/conf (i think thats right)

what script is it that is terminating?
 

shaskins

Member
Dec 12, 2002
9
0
151
Tried replacing /usr/local/apache/conf httpd.conf with older version and no success.

The script that is terminating is your script that I pasted into a file.

Seems like it gets about 75% done processing domains and then returns to prompt with &Terminated&

I have tried to run several times to see if it gets a little furthur each time with no success.

Is there a way to verbosely run the script so I can see exactly where it is failing, or a log file somewhere?

Thanks in Advance,

Frustrated in Colorado
 

hostultra

Well-Known Member
Aug 21, 2002
167
0
166
It probably means your server ran out of memory
That script loads the apache log files into memory so it will take a huge amount of memory to run the script

I just made it as a quick fix, so this didnt matter to me because i only needed to run it once
 

shaskins

Member
Dec 12, 2002
9
0
151
You were right, after looking at my /usr/local/apache/domlogs folder I had over 3GB of log files. After all last ditch efforts I finally just deleted all the log files which fixed my problem but of course not having any historical data.

The script though works great! Thanks for the input and solution.

--Shawn
 

NNNils

Well-Known Member
Sep 17, 2002
580
0
166
I also have this problem, but just on some accounts, not on all.

And also I never used 6.0

I used 5.3 S116 and when the problems arose I upgraded to R117 to see if that would help.

Does anybody have a clue in this???

It is all since my server used 83% of its memory.

Then my provider deleted all logs for me, so that should be fixed.
 
Last edited: