USB Storage usage on Status page + New status bar

ramik

Neuer User
Mitglied seit
3 Mai 2007
Beiträge
168
Punkte für Reaktionen
0
Punkte
16
I made a couple of changes on the status page of dsmod (status.cgi)

1) I changed the status bar style to be similar to the one used in ipcop, code:
Code:
stat_bar() {
	percent=$1; let bar="percent*4"; let grey="(100-percent)*4"
	#echo '<p><img src="/images/green.png" width="'"$bar"'" height="10" border="0" alt=""><img src="/images/grey.png" width="'"$grey"'" height="10" border="0" alt=""> &nbsp;&nbsp;'$percent' %</p>'
	cat << EOF
<table><tr><td>
<table width='400' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:#a0a0a0;width:400px;height:10px;'>
<tr>
<td width='$bar' bgcolor='#a0a0a0' style='background-color:#a0a0a0;border-style:solid;border-width:1px;border-color:#e2e2e2'></td>
<td width='$grey' bgcolor='#e2e2e2' style='background-color:#e2e2e2;border-style:solid;border-width:1px;border-color:#e2e2e2'><img src='/images/null.gif' width='1' height='1' alt='' /></td>
</tr>
</table>
</td>
<td>
$percent %</td>
</tr>
</table>
EOF
}

2) I added the usb storage usage percentage view on front page, currently i have only 1 usb attached, so i don't know how will the code manage with more than 1.

code:
Code:
has_usb() {
        if mount | grep " on /var/media/ftp/" > /dev/null ; then
 		return 1
	fi
	return 0
}

Code:
has_usb
if [ "$?" == "1" ]; then
sec_begin 'USB Storage'

total="$(df | grep "/media/ftp/" | awk '{print $2}')"
used="$(df | grep "/media/ftp/" | awk '{print $3}')"
let percent="100*used/total"
echo "<p>$used of $total KB used</p>"
stat_bar $percent
sec_end
fi

 
Perhaps you can attach a voting? Maybe we can also offer multiple designs although I don't know how we can do this at the moment.

Greets Oliver
 
voting for what ? poll you mean about how nice is it? or to add usb storage info to ds mod trunk?
 
Sorry I expected this question. ;-)
I meant a voting for your design change.

Greets Oliver
 
if for changing the design, then i think that a whole redesign should be made to respect this new Freetz name...

I step ahead to do so, if you say that it is possible.
And anyway, even if it is not needed, now i have it in my changes to make on freetz, at least my version :cool:
 
oh my goodness...i like the idea to c my used storage space...
i don´t need colr changes...but i will try ur changings...thx for that idea
 
i like it also
 
unfortunately it doesn't work with multiple usb storage devices.
I am trying to make it do this too, but i still don't know how to use awk or sed in a way to let me process one line at a time of the df command, any ideas on how can this be done?

i already lost the lunch time to try to make them but still stuck there...

i also started to look into the possibility to put the device name and description in the status window, but code should analyze a couple of files to be able to extract the name...

{who can make me a gift of a linux shell/cgi programming book ;)}
 
While this info may be nice for some users, I wouldn't include in in the status page. Calling external commands takes time, and especially "df" may take some time to get the information from the disk. During this time the box would not respond.

You can make a subpage Status/USB like Status/Logs.
 
If we are talking about performance issues here, then the current status page is slow, as for each of the rows it of status it goes to calculate values, i don't thing that df will go and check all files on all drives to get the status it shows, it is instantaneous, so it must find values in some other way.

anyway, adding a more status page will be interesting too, especially that i am making too a graphical views for some statistics using the rrdtool for fritz.
 
Maybe this helps you?
Code:
has_usb
if [ "$?" == "1" ]; then
sec_begin 'USB Storage'
for name in `ls /var/media/ftp`
do
	total="$(df | grep "/media/ftp/$name" | awk '{print $2}')"
	used="$(df | grep "/media/ftp/$name" | awk '{print $3}')"
	let percent="100*used/total"
	echo "<p>$used of $total KB used</p>"
	stat_bar $percent

done
sec_end
fi
but it is not a very good solution and really slow....
and it only works if all the directories in /var/media/ftp are actually a mount point...
 
i don't thing that df will go and check all files on all drives to get the status it shows, it is instantaneous

No, df will not read all files for the status, it will read some summary information from the filesystem. But it is only instantaneous if that information is already in memory, otherwise it must be read from disk, which means USB1.1 in this case. And we know that the box doesn't have that much RAM for cache, so it is likely to drop (part of) that information from the cache.

I know that the status page is already slow, but I would rather improve the speed that slow it down even more.
 
ok...i tried it on my status.cgi
but it still throws an error...
whats wrong here? please...
Code:
echo 'info' > /proc/tffs
percent="$(cat /proc/tffs | grep '^fill=')"
percent="${percent#fill=}"
let tffs_size="$(printf "%d" "0x$(cat /proc/mtd | grep tffs | head -n1 | awk '{print $2}')")/1024"
let tffs_used="tffs_size*percent/100"
echo "<p>$tffs_used von $tffs_size KB belegt</p>"
stat_bar $percent

sec_end

has_usb
if [ "$?" == "1" ]; then
sec_begin 'USB Storage'
for name in `ls /var/media/ftp`
do
total="$(df | grep "/media/ftp/" | awk '{print $2}')"
used="$(df | grep "/media/ftp/" | awk '{print $3}')"
let percent="100*used/total"
echo "<p>$used KB of $total KB used on $name</p>"
stat_bar $percent
done
sec_end

has_swap
if [ "$?" == "0" ]; then
sec_begin 'Swap-Speicher (RAM)'
total="$(cat /proc/meminfo | grep '^SwapTotal:' | sed s/[^0-9]//g)"
free="$(cat /proc/meminfo | grep '^SwapFree:' | sed s/[^0-9]//g)"
cached="$(cat /proc/meminfo | grep 'SwapCached:' | sed s/[^0-9]//g)"
let usedwc="total-cached-free"
let percent="100*usedwc/total"
echo "<p>$usedwc von $total KB belegt (ohne Cache $cached KB)</p>"
stat_bar $percent
sec_end
fi

stat_button 'restart_dsld' 'DSL-Reconnect'
stat_button 'cleanup' 'TFFS aufräumen'
stat_button 'fw_attrib' 'Attribute bereinigen'
stat_button 'downgrade' 'Downgrade-Mod'
stat_button 'firmware_update' 'Firmware-Update'
stat_button 'reboot' 'Reboot'

cgi_end
the error is, that the end is unexpected or fi is missing and so on...

hope its a not to bad
 
Zuletzt bearbeitet:
Zwischen sec_end und has_swap fehlt das fi.

MfG Oliver
 
soo...nach einem bissel fummeln mit seedyx es es jetzt geschafft...
sicherlch nicht die schnellste lösung...aber ne schöne...rein optisch zumindest
Code:
has_usb
if [ "$?" == "1" ]; then
sec_begin 'USB Storage'
for name in `ls /var/media/ftp`
do
total="$(df -m | grep "/media/ftp/$name" | awk '{print $2}')"
used="$(df -m | grep "/media/ftp/$name" | awk '{print $3}')"
let percent="100*used/total"
echo "<p>$used KB von $total KB auf $name belegt</p>"
stat_bar $percent
done
sec_end
fi
 

Anhänge

  • usb.JPG
    usb.JPG
    46.9 KB · Aufrufe: 38
Zuletzt bearbeitet:
i also made mine to give a link to ftp view on the drive name:
Code:
echo "<p>$used KB von $total KB auf [B]<a href="ftp://fritz.box/$name">$name</a>[/B] belegt</p>"
 
i am sorry, but this assume, that the whole drive is a ftp driectory...
but as an example i am using dirfrent folders as ftp...and never the whole disk...
but keep doin...the idea iss great...
 
... if it is to slow, this one might(!) speed it up a little, using only one "df" (I have no Box to test it out):
Code:
df -k | sed -n 's%/var/media/ftp/%%p' | tr -d '%' | awk '{print "echo \"<p> "$3" KB von "$2 " KB auf "$6  " belegt</p>\"" ; print "stat_bar " $5 }'
I also used "df -k" for it states "KB" or you might want it to change to MB and "-m" if you like it more...

Jörg
 
This is probably a little better, also further improvable.

But the main problem remains. Sometimes "df" needs to read a significant amount of data from the disk to show the results.
 
Holen Sie sich 3CX - völlig kostenlos!
Verbinden Sie Ihr Team und Ihre Kunden Telefonie Livechat Videokonferenzen

Gehostet oder selbst-verwaltet. Für bis zu 10 Nutzer dauerhaft kostenlos. Keine Kreditkartendetails erforderlich. Ohne Risiko testen.

3CX
Für diese E-Mail-Adresse besteht bereits ein 3CX-Konto. Sie werden zum Kundenportal weitergeleitet, wo Sie sich anmelden oder Ihr Passwort zurücksetzen können, falls Sie dieses vergessen haben.