Miscellaneous Code
  Home arrow Miscellaneous Code arrow Disk Space
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS CODE

Disk Space
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-07-04

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    This utility shows you disk utilization for a given storage device.

    It performs a SNMP walk to gather the storage spaces that your system has. Then you simply click on the storage unit and it will show you its capacity, used space & free space. Presentation of data is in text and a pie chart.

    Default settings are the lpbk int (127.0.0.1) and community string is set to "public".

    By : EvilivE

    <?
    function ListDevices(&$hostname, &$community){
    echo "
    <html>
    <head>
    <title>Storage Information</title>
    <head>
    <body>
    <center>
    <table cellpadding=0 cellspacing=0 border=1 width=100%>
    <tr bgcolor=\"#e5e5e5\">
    <td width=33% align=center>hrStorageIndex</td>
    <td width=33% align=center>hrStorageType</td>
    <td width=33% align=center>hrStorageDescr</td>
    </tr>";

    $hrStorageIndex = snmpwalk($hostname, $community, ".1.3.6.1.2.1.25.2.3.1.1");
    $hrStorageType = snmpwalk($hostname, $community, ".1.3.6.1.2.1.25.2.3.1.2");
    $hrStorageDescr = snmpwalk($hostname, $community, ".1.3.6.1.2.1.25.2.3.1.3");

    for($i = 0; $i < sizeof($hrStorageIndex); $i++){
    echo "
    <tr>
    <td width=33% align=center><a href=\"".$_SERVER["PHP_SELF"]."?action=2&storageindex=".$hrStorageIndex[$i]."\">".$hrStorageIndex[$i]."</a></td>
    <td width=33% align=center>";

    $type = substr($hrStorageType[$i], strlen($hrStorageType[$i]) - 1);
    switch($type){
    case 0:
    echo "Network Disk";
    break;
    case 1:
    echo "Other";
    break;
    case 2:
    echo "Ram";
    break;
    case 3:
    echo "Vrtual Memory";
    break;
    case 4:
    echo "Fixed Disk";
    break;
    case 5:
    echo "Removable Disk";
    break;
    case 6:
    echo "Floppy Disk";
    break;
    case 7:
    echo "Compact Disk";
    break;
    case 8:
    echo "Ram Disk";
    break;
    case 9:
    echo "Flash Memory";
    break;
    default:
    echo "Unknown";
    }

    echo " </td>
    <td width=33% align=center>".$hrStorageDescr[$i]."</td>
    </tr>";
    }

    echo "
    </table>
    </center>
    </body>
    </html>";
    }

    function DetailedInfo(&$hostname, &$community, $storageIndex){
    echo "
    <html>
    <head>
    <title>Disk Usage</title>
    </head>
    <body>";

    $hrStorageDescr = snmpget($hostname, $community, ".1.3.6.1.2.1.25.2.3.1.3.".$storageIndex);
    $hrStorageSize = snmpget($hostname, $community, ".1.3.6.1.2.1.25.2.3.1.5.".$storageIndex);
    $hrStorageUsed = snmpget($hostname, $community, ".1.3.6.1.2.1.25.2.3.1.6.".$storageIndex);
    $hrStorageAllocationUnits = snmpget($hostname, $community, ".1.3.6.1.2.1.25.2.3.1.4.".$storageIndex);

    $usedBytes = $hrStorageUsed * $hrStorageAllocationUnits;
    $freeBytes = ($hrStorageSize - $hrStorageUsed) * $hrStorageAllocationUnits;
    $capacity = $hrStorageSize * $hrStorageAllocationUnits;
    $usedBytesPer = round(($usedBytes / $capacity) * 100, 2);
    $freeBytesPer = round(($freeBytes / $capacity) * 100, 2);
    $percentToImage = round(($usedBytes / $capacity) * 100);

    echo "
    <font face=\"Courier\" size=4 color=\"#000000\">
    <center>
    <table cellpadding=0 cellspacing=0 width=75% border=0>
    <tr><td width=100% align=center colspan=4><b>".$hrStorageDescr."</b><br> </td></tr>";

    if($capacity < 1073741824){
    $usedMBytes = round($usedBytes / pow(2,20), 2);
    $freeMBytes = round($freeBytes / pow(2,20), 2);
    $capacityMBytes = round($capacity / pow(2,20), 2);
    echo "
    <tr>
    <td width=20% align=right>Used Space:</td>
    <td width=50% align=center>".number_format($usedBytes)." Bytes</td>
    <td width=15% align=center>".$usedMBytes." MB</td>
    <td width=15% align=center>".$usedBytesPer."%</td>
    </tr>
    <tr>
    <td width=20% align=right>Free Space:</td>
    <td width=50% align=center>".number_format($freeBytes)." Bytes</td>
    <td width=15% align=center>".$freeMBytes." MB</td>
    <td width=15% align=center>".$freeBytesPer."%</td>
    </tr>
    <tr>
    <td width=20% align=right>Capacity:</td>
    <td width=50% align=center>".number_format($capacity)." Bytes</td>
    <td width=15% align=center>".$capacityMBytes." MB</td>
    <td width=15% align=center> </td>
    </tr>";
    } else {
    $usedGBytes = round($usedBytes / pow(2,30), 2);
    $freeGBytes = round($freeBytes / pow(2,30), 2);
    $capacityGBytes = round($capacity / pow(2,30), 2);
    echo "
    <tr>
    <td width=20% align=right>Used Space:</td>
    <td width=50% align=center>".number_format($usedBytes)." Bytes</td>
    <td width=15% align=center>".$usedGBytes." GB</td>
    <td width=15% align=center>".$usedBytesPer."%</td>
    </tr>
    <tr>
    <td width=20% align=right>Free Space:</td>
    <td width=50% align=center>".number_format($freeBytes)." Bytes</td>
    <td width=15% align=center>".$freeGBytes." GB</td>
    <td width=15% align=center>".$freeBytesPer."%</td>
    </tr>
    <tr>
    <td width=20% align=right>Capacity:</td>
    <td width=50% align=center>".number_format($capacity)." Bytes</td>
    <td width=15% align=center>".$capacityGBytes." GB</td>
    <td width=15% align=center> </td>
    </tr>";
    }

    echo "
    <tr>
    <td width=100% align=center colspan=4> <p><img src=\"".$_SERVER["PHP_SELF"]."?action=3&percent=".$percentToImage."\"></td>
    </tr>
    </table>
    </center>
    </font>
    </body>
    </html>";
    }

    function GD2DPie($perUsed){
    $perFree = 100 - $perUsed;
    $endUsed_startFree = ceil((360 / 100) * $perUsed);
    $img = imagecreate(300, 300);
    $bg = imagecolorallocate($img, 255, 255, 255);
    $usedColor = imagecolorallocate($img, 0, 0, 200);
    $freeColor = imagecolorallocate($img, 225, 0, 200);
    imagearc($img, 150, 150, 250, 250, 0, $endUsed_startFree, $usedColor);
    imageline($img, 150, 150, 275, 150, $usedColor);
    imageline($img, 150 + (cos(deg2rad($endUsed_startFree))*(250/2)), 150 + (sin(deg2rad($endUsed_startFree))*(250/2)), 150, 150, $usedColor);
    imagefilltoborder($img, 150 + (cos(deg2rad(($endUsed_startFree)/2))*(250/4)), 150 + (sin(deg2rad(($endUsed_startFree)/2))*(250/4)), $usedColor, $usedColor);
    imagearc($img, 150, 150, 250, 250, $endUsed_startFree, 360, $freeColor);
    imageline($img, 150 + (cos(deg2rad($endUsed_startFree))*(250/2)), 150 + (sin(deg2rad($endUsed_startFree))*(250/2)), 150, 150, $freeColor);
    imageline($img, 150, 150, 275, 150, $freeColor);
    imagefilltoborder($img, 150 + (cos(deg2rad(($endUsed_startFree+360)/2))*(250/4)), 150 + (sin(deg2rad(($endUsed_startFree+360)/2))*(250/4)), $freeColor, $freeColor);
    header("Content-type = image/png");
    imagepng($img);
    imagedestroy($img);
    }

    $hostname = "127.0.0.1"; // change this accordingly
    $community = "public"; // public is default but most likely not "public"

    if (empty($_GET["action"])){
    $action = 1;
    } else {
    $action = $_GET["action"];
    }

    switch($action){
    case 1:
    ListDevices($hostname, $community);
    break;
    case 2:
    DetailedInfo($hostname, $community, $_GET['storageindex']);
    break;
    case 3:
    GD2DPie($_GET['percent']);
    break;
    default:
    die("Unable to process request!");
    }

    ?>
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Miscellaneous Code Articles
    More By Codewalkers

     

    IBM® developerWorks developerWorks - FREE Tools!


    NEW! "ebook: Exploring IBM SOA Technology & Practice

    Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success.
    FREE! Go There Now!


    NEW! A Layered approach to delivering security-rich Web applications

    As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper.
    FREE! Go There Now!


    NEW! Achieving True Agility -- How process can change the behavior of your tools

    Achieving true agility is a never-ending effort. We will showcase how you can become agile incrementally, a few practices at the time.Which practices should any agile team strive to adopt? What additional practices should you consider based on your needs to scale? Adopting practices are however made much easier with the right tool support. What about if your tools adapt to your practices? We will take a look at how the Jazz technology can be leveraged to make your process change the behavior of your tools.
    FREE! Go There Now!


    NEW! Download IBM WebSphere Portal V6.1 beta code

    Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization.
    FREE! Go There Now!


    NEW! Info 2.0: Harnessing the power of Web 2.0 and Enterprise Mashups

    Listen to this webcast to get an overview of Info 2.0 and a technical demo of how to quickly build an enterprise mashup. IBM's Info 2.0 technology leverages emerging Web 2.0 technologies such as mashups, feeds, AJAX, and JSON in order to simplify assembly of information using feeds and services. Come learn about the technical elements of Info 2.0 including the Feed Generation framework, Mashup Engine, and mashup assembly components. Learn how to pull information from databases, departmental information, and the Web to create mashups critical to your company’s success. We will also discuss best practices to help you get started.
    FREE! Go There Now!


    NEW! Rational Talks to You: Manage RUP-based CMMI initiatives

    Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered!
    FREE! Go There Now!


    NEW! Run your first CICS application on a PC using TXSeries for Windows

    Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1.
    FREE! Go There Now!


    NEW! Trial download: IBM Rational Method Composer V7.2

    Get a free trial download of the latest version of IBM Rational Method Composer V7.2 which helps you deliver customized yet consistent process guidance to your project teams and IT organization, and includes the latest version of IBM Rational Unified Process (RUP), which has provided process guidance to teams since 1996.
    FREE! Go There Now!


    NEW! Webcast: Accelerating Software Innovation with System z

    Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time.
    FREE! Go There Now!


    Refresh! IBM Rational Systems Development Solution eKit

    With IBM Rational Systems Development Solution, you can deliver products faster with higher quality. Within this kit, Read the “Model Driven Systems Development” white paper to see how to improve product quality and communication. Then check out the rest of the e-Kit to learn more about important topics that can affect the success of any software project through customer examples, tutorials, informative Webcasts, and best practices for designing, building and managing systems. From start to finish, at every stage in your projects, Rational Systems Development Solution can help your company reach its full potential.
    FREE! Go There Now!



    All FREE IBM® developerWorks Tools!

    MISCELLANEOUS CODE ARTICLES

    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...
    - Model Data and Validation Rules for a Generi...
    - Building a Generic Model for the CodeIgniter...
    - upload image to database sql
    - Random Password Generator
    - BCroot, get the root of a number with BC fun...
    - Find pi in a high precision
    - [PHP5] FORMCHECKER : data validation
    - SPL and ITERATOR : examples
    - Xml with Rss Feeds





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek