Bandwidth
From LinodeWiki
http://www.linode.com/forums/viewtopic.php?t=1558
Example Output:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<linData>
<host>
<host>host41.linode.com</host>
<hostLoad>low</hostLoad>
<pendingJobs>0</pendingJobs>
</host>
<upSince>2005-03-16 11:49:34</upSince>
<cpuConsumption>0.01</cpuConsumption>
<bwdata>
<year>2005</year>
<month>3</month>
<max_avail>39728447488</max_avail>
<rx_bytes>4692233</rx_bytes>
<tx_bytes>2963967</tx_bytes>
<total_bytes>7656200</total_bytes>
</bwdata>
</linData>
You can download a perlscript that stops webpages when their transfer limit(s) have been reached. Look here to see what I mean:
http://64.22.109.195/1/bw.html
It starts/stops my webpages depending on how much transfer I have left for the month. You're welcome to copy it.
P.S. Run the script as a cronjob. Instructions are inside the script. Running the cronjob less often than once an hour or so, makes you a considerate user.
--Harmone 19:07, 24 Jun 2007 (EDT)
[edit] PHP script to retrieve the bandwidth in a nicer way
Here's a little script I've wrote, to use from command line: (you'll need to have php client for that... install php-cli)
#!/usr/bin/php
<?php
function human ( $num ) {
if ($num<1024) {
$str = strval($num)." K";
} elseif ($num<(1024*1024)) {
$str = strval(intval(floor($num/1024)))." M";
} else {
$str = strval(intval(floor($num/(1024*1024))))." G";
}
return $str;
}
function kb ( $bytes ) {
$bytes /=1024;
return $bytes;
}
exec("wget -q --output-document=/tmp/mybw.xml http://www.linode.com/members/info/?user=yourusername",$output);
$xml = simplexml_load_file('/tmp/mybw.xml');
$bwdata = $xml->bwdata;
$year = $bwdata->year;
$month = $bwdata->month;
// $bw_max = round ( GB( floatval( $xml->bwdata->max_avail ) ), 2 ) ;
$dl = round(kb(floatval($bwdata->rx_bytes)),2);
$ul = round(kb(floatval($bwdata->tx_bytes)),2);
$total = round(kb(floatval($bwdata->total_bytes)),2);
$limit = round(kb(floatval($bwdata->max_avail)),2);
$precentage = round($total/$limit*100,0)."%";
echo("MyBandWidth, version 0.1\n");
echo("\n");
echo("Month: $month/$year\n");
echo("Uploaded: ".human($ul)."\n");
echo("Downloaded: ".human($dl)."\n");
echo("Total use: ".human($total)." from ".human($limit)." allowed ($precentage)\n");
echo("\n");
?>
In my system it's in /usr/bin/mybw, but it doesn't have to be, as long as it is executable.
Now - just type wherever you are mybw (if it's in /usr/bin or so) or run it with php command, and evuala.
Hope it helps... post questions in my talk page. Peleg 19:51, 30 May 2008 (EDT)
