Bernard Li wrote:
Author: bli
Date: 2006-01-16 00:29:48 -0600 (Mon, 16 Jan 2006)
New Revision: 3403
Modified:
trunk/initrd_source/skel/etc/init.d/functions
trunk/sbin/si_monitor
trunk/sbin/si_monitortk
Log:
- Bandwidth (speed) now reported in MB/s if > 999.99 KB/s
Bernard,
I think is better to format the bandwidth speed in si_monitortk and keep
the "raw" data on clients.xml. In this way is easier (and above all
faster) to sort clients by attributes, in this case by speed. In fact
all the not-numeric attributes are sorted like strings, so now for
example 300KB/s results > 2MB/s (because 3 > 2...)
If you don't see contraindications I'll go to check this patch...
Cheers,
-Andrea
Index: sbin/si_monitortk
===================================================================
--- sbin/si_monitortk (revision 3408)
+++ sbin/si_monitortk (working copy)
@@ -667,6 +667,14 @@
# Format the bandwidth.
if (!$client->{$mac}->{'speed'}) {
$client->{$mac}->{'speed'} = '-';
+ } else {
+ if ($client->{$mac}->{'speed'} < 1000) {
+ $client->{$mac}->{'speed'} =
+ sprintf("%.3fKB/s", $client->{$mac}->{'speed'});
+ } else {
+ $client->{$mac}->{'speed'} =
+ sprintf("%.3fMB/s", $client->{$mac}->{'speed'} / 1000);
+ }
}
# Format the total amount of RAM.
if (defined($client->{$mac}->{'mem'})) {
Index: sbin/si_monitor
===================================================================
--- sbin/si_monitor (revision 3408)
+++ sbin/si_monitor (working copy)
@@ -269,7 +269,7 @@
} elsif (s/^status=//) {
$client->{'status'} = $_;
} elsif (s/^speed=//) {
- $client->{'speed'} = $_;
+ $client->{'speed'} = int($_);
} elsif (s/^log=//) {
$client->{'log'} = $_;
}
Index: initrd_source/skel/etc/init.d/functions
===================================================================
--- initrd_source/skel/etc/init.d/functions (revision 3408)
+++ initrd_source/skel/etc/init.d/functions (working copy)
@@ -1438,13 +1438,7 @@
TOT=`echo $LIST | bc`
# Evaluate bandwidth.
- speednum=`echo "scale=2; (($TOT - $DISKSIZE) - $CURR_SIZE) / $REPORT_INTERVAL" | bc`
- if [ `echo "$speednum > 999.99" | bc` != 0 ]; then
- speednum=`echo "scale=2; $speednum / 1000" | bc`
- speed=$speednum"MB/s"
- else
- speed=$speednum"KB/s"
- fi
+ speed=`echo "scale=2; (($TOT - $DISKSIZE) - $CURR_SIZE) / $REPORT_INTERVAL" | bc`
# Evaluate status.
CURR_SIZE=$(($TOT - $DISKSIZE))