Draws a simple GD pie chart showing used space over total space. Requires GD of course.
You can also find more scripts on my site
hereBy : andrew
<?php
define("DISK","/home/"); //Enter the Drive/Mount point/Directory that you want to generate a space usage graph for.
$total = round(disk_total_space(DISK)/1024/1024,2); //Get the total diskspace
$free = round(disk_free_space(DISK)/1024/1024,2);
$used = $total - $free; //Find used space
$used = round(($used/$total)*100); //Calculate used space when rounded
$free = round(($free/$total)*100); //Calculate free space
//Generate pie chart
define("WIDTH", 500); //Width may break if changed
define("HEIGHT", 220); //Again height may break it when changed
$data[0] = $used;
$data[1] = $free;
$img = imagecreate(WIDTH-100, HEIGHT); //Start the images
$background = $white = imagecolorallocate($img, 112,128,144); //Set background
$black = imagecolorallocate($img, 0, 0, 0); //Set colours, black in this case
$center_x = (int)WIDTH/2; //Calculate image centre for x
$center_y = (int)HEIGHT/2; //Calculate image centre for y
imagerectangle($img, 0, 0, WIDTH-101, HEIGHT-1, $black); //Draw the backrgound border
$color[0] = imagecolorallocate($img, 159,182,205);
$color[1] = imagecolorallocate($img, 198,226,255);
$last_angle = 0;
//Draw the pie chart on the percentage of disk space
for($i=0; $i<count($data); $i++) {
$arclen = (360 * $data[$i]) / 100;
imagefilledarc($img, $center_x - 120, $center_y, 200, 200, $last_angle, ($last_angle + $arclen), $color[$i],IMG_ARC_PIE);
$last_angle += $arclen;
}
//Turn the used space into gigabytes
$used = round(($used*$total)/100/1024,2);
imagestring($img, 5, 250, $center + 30,
"Used Space: ".$data[0]."%", $color[0]); //Draw info onto the main shape
imagestring($img, 5, 250, $center + 60,
"Free Space: ".$data[1]."%", $color[1]);
//Same as above but for free space
imagerectangle($img, 240, $center+10, 390, $center+100, $black);
imagestring($img, 5, $center_x, $center + 200,
$used."Gb / ".($total/1024)."Gb", $black);
// Used space / Total Space
header("Content-Type: image/png"); //Content type png
imagepng($img); //Draw image to browser
imagedestroy($img); //Destroy the image resource
?>
| 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 File Manipulation Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
<a href="http://zeus.developershed.com/shonuff.php?blackbird=3853&zoneid=442&source=&dest=http%3A%2F%2Fwww.ibm.com%2Fdeveloperworks%2Fspaces%2Fjazz%3FS_TACT%3D105AGY31%26S_CMP%3DDEVSHED&ismap="><img src="http://images.devshed.com/corp/img/news/jazz01.gif" alt="developerWorks Jazz space" align="left"></a>You've heard the buzz about Jazz... want to know more about it from a developer's perspective? Check out the Jazz space on developerWorks. This space is an up-to-date resource for developers, including technical information about Jazz and products built on Jazz, like Rational Team Concert Express. The Jazz space includes content from a wide variety of sources, including links, feeds, and comments from experts. FREE! Go There Now!
|
|
|
|
Download a free trial version of IBM Rational Developer for System z, software that can help you deliver core development capabilities; the power of Java Platform, Enterprise Edition (Java EE); and rapid application development support to diverse enterprise application development teams. With comprehensive development tools to help create, deploy and maintain traditional enterprise and composite applications, Rational Developer for System z enables developers with different technical backgrounds to easily participate in important technology projects. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration. FREE! Go There Now!
|
|
|
|
Join us for this web seminar to learn how you can defend your web applications from attack. Learn about the 3 most common web application attacks, including how they occur and what can be done to prevent them. We’ll also discuss manual versus automated approaches for scanning and identifying web application vulnerabilities and how IBM Rational AppScan, an automated vulnerability scanner, can help you automate more of what you are doing manually today. FREE! Go There Now!
|
|
|
|
Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services. FREE! Go There Now!
|
|
|
|
Portfolio Management is about effectively managing portfolio value by aligning portfolio investments with business goals. This complimentary e-kit provides a collection of materials that can help you understand how IBM Rational enables and automates best practices for improved governance and clear visibility into portfolio and project performance across the entire IT project lifecycle. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
|
|
|
|
Join this webcast to discover the key requirements for successful change and release management. Learn how to extend your .NET environment to improve productivity and collaboration, and address core problems afflicting team development. In this webcast, we’ll review typical challenges faced by customers and how to resolve them with the IBM Rational Change and Release Management solution, including Rational ClearCase, Rational ClearQuest and Rational Build Forge. Replay is available for 9 months. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to try the IBM SOA Sandbox for people. The SOA Sandbox for people provides a trial environment with the necessary tooling and components required to enable consistent human and process interaction and collaboration, showing how you can improve user experience and business productivity. FREE! Go There Now!
|
|
|
|
IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |