*) Displaying more user friendly Memory Usage statistic

*) Displaying traffic consumed by yacy 
   - this is not finished yet
   - at the moment only outgoing proxy traffic is counted

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@235 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
theli 20 years ago
parent f8de2556f8
commit f9a95b5cb8

@ -109,6 +109,11 @@ you must switch off the proxy to go off-line.
<tr class="TableCellDark"><td>Memory Usage</td><td>
free: #[freeMemory]# | total: #[totalMemory]# | max: #[maxMemory]#
</td></tr>
<tr class="TableCellLight"><td>Traffic</td><td>
In: #[trafficIn]# | Out: #[trafficOut]#
</td></tr>
</table>
<!-- </td></tr></table> -->
</p>

@ -43,9 +43,11 @@
// javac -classpath .:../Classes Status.java
// if the shell's current path is HTROOT
import java.util.Properties;
import java.text.DecimalFormat;
import de.anomic.http.httpHeader;
import de.anomic.http.httpdByteCountInputStream;
import de.anomic.http.httpdByteCountOutputStream;
import de.anomic.server.serverCore;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
@ -168,9 +170,13 @@ public class Status {
// memory usage
Runtime rt = Runtime.getRuntime();
prop.put("freeMemory", Long.toString(rt.freeMemory()));
prop.put("totalMemory", Long.toString(rt.totalMemory()));
prop.put("maxMemory", Long.toString(rt.maxMemory()));
prop.put("freeMemory", bytesToString(rt.freeMemory()));
prop.put("totalMemory", bytesToString(rt.totalMemory()));
prop.put("maxMemory", bytesToString(rt.maxMemory()));
// proxy traffic
prop.put("trafficIn",bytesToString(httpdByteCountInputStream.getGlobalCount()));
prop.put("trafficOut",bytesToString(httpdByteCountOutputStream.getGlobalCount()));
// return rewrite properties
return prop;
@ -200,5 +206,31 @@ public class Status {
return "unknown";
}
}
public static String bytesToString(long byteCount) {
try {
StringBuffer byteString = new StringBuffer();
DecimalFormat df = new DecimalFormat( "0.00" );
if (byteCount > 1073741824) {
byteString.append(df.format((double)byteCount / (double)1073741824 ))
.append(" GB");
} else if (byteCount > 1048576) {
byteString.append(df.format((double)byteCount / (double)1048576))
.append(" MB");
} else if (byteCount > 1024) {
byteString.append(df.format((double)byteCount /(double)1024))
.append(" KB");
} else {
byteString.append(Long.toString(byteCount))
.append(" Bytes");
}
return byteString.toString();
} catch (Exception e) {
return "unknown";
}
}
}

Loading…
Cancel
Save