The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Bandwidth counter screwed up

Discussion in 'General Discussion' started by hostultra, Jan 28, 2003.

  1. hostultra

    hostultra Well-Known Member

    Joined:
    Aug 21, 2002
    Messages:
    167
    Likes Received:
    0
    Trophy Points:
    16
    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
     
  2. orca

    orca Well-Known Member

    Joined:
    Sep 23, 2002
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Switzerland
    I think that's a problem with the latest beta. I had the same.
     
  3. hostultra

    hostultra Well-Known Member

    Joined:
    Aug 21, 2002
    Messages:
    167
    Likes Received:
    0
    Trophy Points:
    16
    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 = &&;

    }
     
  4. orca

    orca Well-Known Member

    Joined:
    Sep 23, 2002
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    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...
     
  5. hostultra

    hostultra Well-Known Member

    Joined:
    Aug 21, 2002
    Messages:
    167
    Likes Received:
    0
    Trophy Points:
    16
    no dont replace anything
    just run it

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

    orca Well-Known Member

    Joined:
    Sep 23, 2002
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Switzerland
    Yeah, got it. Went fine. Anyway, could that have slown down my server?
     
  7. orca

    orca Well-Known Member

    Joined:
    Sep 23, 2002
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Switzerland
    Well, today, the bandwidth was screwed up again...
     
  8. hostultra

    hostultra Well-Known Member

    Joined:
    Aug 21, 2002
    Messages:
    167
    Likes Received:
    0
    Trophy Points:
    16
    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
     
  9. orca

    orca Well-Known Member

    Joined:
    Sep 23, 2002
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Switzerland
    Well, at the mo I'm back to 5.3...
     
  10. hostultra

    hostultra Well-Known Member

    Joined:
    Aug 21, 2002
    Messages:
    167
    Likes Received:
    0
    Trophy Points:
    16
    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
     
  11. orca

    orca Well-Known Member

    Joined:
    Sep 23, 2002
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Switzerland
    Hmm, ok. Gone back to 6.0. Let's see whether this works.
     
  12. orca

    orca Well-Known Member

    Joined:
    Sep 23, 2002
    Messages:
    75
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Switzerland
    Seems to work :)
     
  13. hotice007

    hotice007 Well-Known Member
    PartnerNOC

    Joined:
    Jun 20, 2002
    Messages:
    64
    Likes Received:
    0
    Trophy Points:
    6
    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.
     
  14. hostultra

    hostultra Well-Known Member

    Joined:
    Aug 21, 2002
    Messages:
    167
    Likes Received:
    0
    Trophy Points:
    16
    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
     
  15. shaskins

    shaskins Member

    Joined:
    Dec 12, 2002
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    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.
     
  16. hostultra

    hostultra Well-Known Member

    Joined:
    Aug 21, 2002
    Messages:
    167
    Likes Received:
    0
    Trophy Points:
    16
    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?
     
  17. shaskins

    shaskins Member

    Joined:
    Dec 12, 2002
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    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
     
  18. hostultra

    hostultra Well-Known Member

    Joined:
    Aug 21, 2002
    Messages:
    167
    Likes Received:
    0
    Trophy Points:
    16
    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
     
  19. shaskins

    shaskins Member

    Joined:
    Dec 12, 2002
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    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
     
  20. NNNils

    NNNils Well-Known Member

    Joined:
    Sep 17, 2002
    Messages:
    580
    Likes Received:
    0
    Trophy Points:
    16
    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.
     
    #20 NNNils, Feb 21, 2003
    Last edited: Feb 21, 2003
Loading...

Share This Page