free disk space usage

Discussion of the Web Interface for Transmission, formerly known as Clutch. This applies to all version of Transmission
vasja
Posts: 2
Joined: Wed Sep 09, 2009 1:11 pm

free disk space usage

Postby vasja » Wed Sep 09, 2009 1:19 pm

Hi !

The question is - "Is it possible to add text information about disk usage ( used\free ) at the status box?"
Now there i see number of torrents and up/down speed.

Thanks for answer.

chatainsim
Posts: 3
Joined: Wed Sep 16, 2009 9:08 pm

Re: free disk space usage

Postby chatainsim » Thu Sep 17, 2009 10:55 am

Hello,

i've made some modification on webui to get space disk :

1] Create a file get.js in /usr/share/transmission/web/javascript (linux path here)
touch /usr/share/transmission/web/javascript/get.js
nano /usr/share/transmission/web/javascript/get.js

Code: Select all

var data = new Array();
var i = 0;
var datafile = window.location.href.substring(0,
     window.location.href.lastIndexOf("/") + 1) +
     "./javascript/data.txt";
var url = new java.net.URL(datafile);
var connect = url.openConnection();
var input = new java.io.BufferedReader(
     new java.io.InputStreamReader(
         connect.getInputStream()));
var aLine = ""
while((aLine = input.readLine()) != null) {
    data[i++] = aLine;
    }


As you can see, the file data.txt should be in the same directory /usr/share/transmission/web/javascript/

2] We need to make some modification on the index.html file :
nano /usr/share/transmission/web/index.html
Find this line :
<script type="text/javascript" src="./javascript/jquery/jquery.transmenu.min.js"></script>

Then add before or after this one :

Code: Select all

<script type="text/javascript" src="./javascript/get.js"></script>


3] Another modification in index.html :
Find this line :
<div id="disk_space_container"></div>

Put this between <div></div>:

Code: Select all

Disk Space :
<SCRIPT language = "Javascript">
var temp = ""
temp = data[0];
document.write(temp);
</SCRIPT>

You should have this :
<div id="disk_space_container">Disk Space :
<SCRIPT language = "Javascript">
var temp = ""
temp = data[0];
document.write(temp);
</SCRIPT>
</div>


For this part, there is no need to but on Linux, but the path should be different.

Next i've just make a cron that is check every hours the disk space and put the result in the data.txt file.

touch ~/disk_trans.sh
nano ~/disk_trans.sh

Code: Select all

df /mnt -h | grep -i /mnt | awk {'print "Used:",$3,"- Free:",$4'} >/usr/share/transmission/web/javascript/data.txt

chmod +x ~/disk_trans.sh
crontab -e

Code: Select all

@hourly /root/disk_trans.sh


for every 10 mins :

Code: Select all

0,10,20,30,40,50 * * * * /root/disk_trans.sh


That's all.
The cron launch the script every hours, then put the disk space on data.txt and the javascript in webui just read the data.txt file.

Sorry for my bad english ;)

For any question, just ask me !

ps : the disk space appear in the bottom right corner of webui

vasja
Posts: 2
Joined: Wed Sep 09, 2009 1:11 pm

Re: free disk space usage

Postby vasja » Sun Sep 20, 2009 12:49 pm

Yes at version 1.74 it worked. After update to 1.75 it has broken (nothing display, even "Disk Space..." but at index.html your modifications exists). Also it method works if installed java development kit at my workstation, but I'am a user, not developer and i don't need such software. This method never will include in distributive. Don't want edit by hands webgui-scripts after each update ;)
Аnyway, thanks for help and your time.

Now work at 1.75 becouse install-prefix changed from /usr to /usr/local. (now web-gui scripts at /usr/local/share/transmission/web)

ps. using transmission-daemon-1.75, transmission-web-1.75 on FreeBSD 7.2-STABLE

lkraav
Posts: 6
Joined: Tue Sep 22, 2009 9:04 am

Re: free disk space usage

Postby lkraav » Tue Sep 22, 2009 9:11 am

for some reason firefox on os x pukes for the above java solution with not finding getInputStream() method. so i implemented a nice auto refreshing solution with ajax.

get.js:

Code: Select all

function disk_space() {
        var oRequest = new XMLHttpRequest();
        var sURL  = "http://yourtransmissionmachine:8091/transmission/web/javascript/data.txt";

        var currentTime = new Date();
        var hr = currentTime.getHours();
        var min = currentTime.getMinutes();
        // var sec = currentTime.getSeconds();

        oRequest.open("GET",sURL + '?nocache=' + currentTime.getTime(),false); // make a unique URL to disable browser side caching
        oRequest.setRequestHeader("User-Agent",navigator.userAgent);
        oRequest.send(null);

        document.getElementById('disk_space_container').innerHTML = oRequest.responseText + ' | ' + hr + ':' + min;     
}

window.onload = disk_space; // execute disk_space after whole page with our disk_space_container has been loaded

setInterval(disk_space, 300000); // refresh free disk space every 5 minutes


index.html -> no further modification needed!:

Code: Select all

<div id="disk_space_container">
</div>


edit: some edits to deal with caching etc. safari also needs something like min-width:400px for the div, because when it first sees the div its empty and the text will not be visible when its put there. firefox displays correctly ootb.

chatainsim
Posts: 3
Joined: Wed Sep 16, 2009 9:08 pm

Re: free disk space usage

Postby chatainsim » Mon Sep 28, 2009 5:42 pm

Very nice ! it's better with ajax ;)
i take your solution !

thanks a lot !


Return to “Web Interface”