Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Display CPU usage load

    I want to display the cpu usage % in image, like this:
    http://virusscan.jotti.org/
    any idea how can I do that? Thanks

  • #2
    New Coder
    Join Date
    Jul 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you need 4 different images, each one with 1 pixel width. all with the same height.
    image1 is the left border of your bar.

    image2 is a the bar increment, and on top and bottom a piece of the border, like this:
    .
    |
    .

    image3 is the same as image2 but without the bar increment, just the bottom and top pixels of the border:
    .

    .
    image4 is the right border of the bar.
    then for representing a bar 60% full you should put in the same html table cell:
    image1 once;
    image2 60times;
    image3 40times;
    image4 once;
    remember to put on the img params: border="0"

    This example is the simpliest, no need to create images in php ( requiring gd libraries etc etc), just loops. Of course there are more ways to solve this problem.

    I this explanation I'm assuming you use one pixel bars for each percent unit, but you can always adjust proportions.
    Last edited by SocoNaTromba; 02-08-2006 at 12:38 AM.

  • #3
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,084
    Thanks
    11
    Thanked 100 Times in 98 Posts
    you would need to exec() some linux command to find the current CPU usage and then either create an image or make a table/graph out of that data .. cat /proc/stat shows some cpu usage info but you would still have to parse that.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #4
    New Coder
    Join Date
    Jul 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well I just explained the construction, missed the part of obtaining data.
    thks firepages.

  • #5
    New Coder
    Join Date
    Feb 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. Do you know what php code to use?
    And maybe the width of the image | will just change depending on how much %?
    Last edited by janjalani; 02-08-2006 at 01:01 AM.

  • #6
    New Coder
    Join Date
    Jul 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    varying widths is also a good aproach, since my example contains images that can be extruded horizontally without vertical deformation, but you still need the 4 images.
    No time to create php code, sorry.

  • #7
    New Coder
    Join Date
    Feb 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried making one. But I am having errors. Can you tell me whats wrong?
    Code:
    <?php 
    $uptime = exec('uptime'); 
    $uptimeArray = split(",", $string); 
    array_reverse($uptimeArray); 
    array_pad($uptimeArray, 3); 
    
    echo '<img src="images/bar.jpg" alt="" width="' . $uptime . '" />';
    ?>

  • #8
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,084
    Thanks
    11
    Thanked 100 Times in 98 Posts
    This works for me ...

    PHP Code:
    <?php
    $uptime 
    exec('uptime');
    $uptime explode(",",$uptime);
    //print_r($uptime);
    $uptime explode(':',$uptime[2]);
    echo 
    '<img src="images/bar.jpg" alt="" width="' $uptime[1] . '" />';
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #9
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,084
    Thanks
    11
    Thanked 100 Times in 98 Posts
    # cat /proc/loadavg
    might be useful as well ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #10
    New Coder
    Join Date
    Feb 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ill try it soon!


  •  

    Posting Permissions

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