+ Reply to Thread
Results 1 to 4 of 4

Thread: Display server load for Windows server

  1. #1
    Join Date
    Sep 2008
    Posts
    6

    Display server load for Windows server

    Hello. I've been searching around for a script to display server load for my Windows server hosted here, but I can only find scripts that will work on Unix systems. The one I've found that's supposed to work on Windows server gives me an error:

    Warning: (null)(): Invalid ProgID, GUID string, or Moniker: No description available in C:\Inetpub\vhosts\user\httpdocs\windowsuptime.p hp on line 8
    PHP has encountered an Access Violation at 01C3E3F8

    This is the souce code:

    Code:
    <?php
    // PHP 5
     
    header("Content-type: image/png");
     
    function getServerLoad(){
     
        $wmi = new COM("Winmgmts://");
        $server = $wmi->execquery("SELECT LoadPercentage FROM Win32_Processor");
     
        foreach($server as $cpu){
     
            return $cpu->loadpercentage;
        }
    }
     
    $load     = getServerLoad();
    $img     = @imagecreate(107, 12) or die("Server ondersteunt geen GD library...");
     
    $background_color     = imagecolorallocate($img, 255, 255, 255);
    $border_color         = imagecolorallocate($img, 197, 197, 197);
    $procent             = imagecolorallocate($img, 0, 0, 0);
     
    if($load < 33){
     
        $load_color     = imagecolorallocate($img, 149, 191, 77); // Green
     
    }elseif($load >= 33 && $load < 66){
     
        $load_color     = imagecolorallocate($img, 213, 184, 55); // Orange
     
    }else{
     
        $load_color     = imagecolorallocate($img, 186, 83, 83); // Red
    }
     
    imagerectangle($img, 0, 0, 106, 11, $border_color);
    imagefilledrectangle($img, 3, 3, 3 + $load, 8, $load_color);
     
    imagestring($img, 1, 50, 2, $load . "%", $procent);
     
    // Create Image
    imagepng($img);
    imagedestroy($img);
     
    ?>
    Can anyone help make this work or suggest another solution to show the Windows server load on a page??

    Thanks in advance for any help.
    Patty

  2. #2
    Join Date
    Sep 2008
    Posts
    6
    And here's another one that's supposed to work on Windows as well but is also giving the same error:

    Code:
    <?php
    function get_server_load($windows = 0) {
        $os = strtolower(PHP_OS);
        if(strpos($os, "win") === false) {
     if(file_exists("/proc/loadavg")) {
         $load = file_get_contents("/proc/loadavg");
         $load = explode(' ', $load);
         return $load[0];
     }
     elseif(function_exists("shell_exec")) {
         $load = explode(' ', `uptime`);
         return $load[count($load)-1];
     }
     else {
         return "";
     }
        }
        elseif($windows) {
     if(class_exists("COM")) {
         $wmi = new COM("WinMgmts:\\\\.");
         $cpus = $wmi->InstancesOf("Win32_Processor");
         
         $cpuload = 0;
         $i = 0;
         while ($cpu = $cpus->Next()) {
       $cpuload += $cpu->LoadPercentage;
       $i++;
         }
         
         $cpuload = round($cpuload / $i, 2);
         return "$cpuload%";
     }
     else {
         return "";
     }
        }
    }
    ?>
    I hope someone can help with this.
    TIA
    Patty

  3. #3
    Join Date
    Sep 2008
    Posts
    6
    Nobody???
    Patty

  4. #4
    Join Date
    Apr 2003
    Location
    New Jersey, USA
    Posts
    4,639
    You'd be best off putting in a helpdesk ticket about this.
    Need help?

    Feel free to contact me via E-mail: aric.p@hostdime.com
    Click HERE to submit a ticket to the helpdesk
    ----
    Now Shipping:
    cPanel: A User's Guide
    and:
    Web Host Manager Administration Guide

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts