Ain't this cool?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zef Hemel
    Member
    • Jan 2001
    • 78

    Ain't this cool?

    Have been playing with the PHP GD library. Using a cronjob I can now generate a chart of my server's activity in the past 15 minutes (avatar) or past hour:


    I think it's really cool.
  • chrispadfield
    Senior Member
    • Aug 2000
    • 5366

    #2
    that is cool. Any chance of posting the code you are using?
    Christopher Padfield
    Web Based Helpdesk
    DeskPRO v3.0.3 Released - Download Demo Now!

    Comment

    • Zef Hemel
      Member
      • Jan 2001
      • 78

      #3
      Sure, this is the serverload.php (executed every minute by a cronjob):
      PHP Code:
      <?php
      function loadaverage() {
          
      $path='/proc/loadavg';
          if(
      file_exists($path))
          {
              
      $filesize=filesize($path);
              
      $filenum=fopen($path,'r');
              
      $filestuff=@fread($filenum,6);
              
      fclose($filenum);
              
      $loadavg=explode(' ',$filestuff);
          }
          else
          {
              
      $loadavg_raw exec("uptime");
              
      $loadavg_raw split("load averages?: "$loadavg_raw);
              
      $loadavg explode (','$loadavg_raw[1]);
          }
          return (
      trim($loadavg[0]));
      }

      $lines file("loadlog.txt");
      if(
      count($lines)>75)
          
      array_shift($lines);
      $lines[] = loadaverage()."\n";

      $fp fopen("loadlog.txt""w");
      for(
      $i=0;$i<count($lines);++$i)
          
      fputs($fp$lines[$i]);
      fclose($fp);
      ?>
      This is the code for the drawload.php (the chart I just showed you):
      PHP Code:
      <?php

      function drawload($load)
      {
          global 
      $image$bg$green$maxload;
          static 
      $x 25;

          if(!
      $load)
              return 
      false;
          
      $y 75 round(75 * ((float)$load/(float)$maxload));
          
      //echo "$load = $x, $y<br>";
          
      ImageFilledRectangle($image$x$y$x+275$green);

          
      $x += 4;
      }

      function 
      maxload()
      {
          global 
      $loads;

          
      $max 0;
          for(
      $i=0;$i<count($loads);++$i)
          {
              if((float)
      $loads[$i]>(float)$max)
                  
      $max $loads[$i];
          }
          return 
      $max;
      }

      $loads file("loadlog.txt");
      $maxload maxload();
      if(
      $maxload 3)
          
      $maxload 3;

      $image ImageCreate(33075);
      $bg ImageColorAllocate($image000);
      $green ImageColorAllocate($image02550);
      ImageRectangle($image0033075$black);
      for(
      $i=0;$i<count($loads);++$i)
          
      drawload($loads[$i]);
      ImageString($image100, (float)$maxload$green);
      ImageString($image1032, (float)((float)$maxload/2), $green);
      ImageString($image1065"0.00"$green);

      Header("Content-type: image/jpeg");
      Imagejpeg($image);
      ImageDestroy($image);
      ?>
      I have a customized version for the avatar (in which serverload.php generates the .jpg image for the avatar, so it doesn't have to be regenerated every hit the avatar gets.

      Comment

      • chrispadfield
        Senior Member
        • Aug 2000
        • 5366

        #4
        cool! will try this soon.
        Christopher Padfield
        Web Based Helpdesk
        DeskPRO v3.0.3 Released - Download Demo Now!

        Comment

        • Stallion
          Senior Member
          • Apr 2000
          • 704

          #5
          The only problem is your avatar is hosted on the server of the forum. So even when you set your avatar in the user CP, it stores the current load image...regardless of how often you update the avatar.

          What you need to do is add a section to your script which will update the new avatar on the server. Not too hard to do if you have an understanding of HTTP and the file upload specifications.

          Comment

          • Zef Hemel
            Member
            • Jan 2001
            • 78

            #6
            You mean that, vBulletin automatically downloads the avatar and stores it in it's database? Hmm, that's to bad. I'd say the easiest thing to do would be to create a hack that allowed external avatars being loaded from another server. Or use other bulletin board software (but I doubt if that's an option).

            Comment

            • Jake Bunce
              Senior Member
              • Dec 2000
              • 46598
              • 3.6.x

              #7
              multiple domain resolutions = bad.

              Comment

              • Stallion
                Senior Member
                • Apr 2000
                • 704

                #8
                Plus there are some privacy issues with doing that...

                Comment

                Related Topics

                Collapse

                Working...