Added network logging for http traffic

Change-Id: I69f571fba23fc03e0d850180650f61b4581e8a25

Former-commit-id: f74b6b4a93 [formerly 7696dd610b5d6f0fc3620db461de68ba06c61699]
Former-commit-id: a912786429
This commit is contained in:
Max Schenkelberg 2012-04-25 17:28:52 -05:00
parent 1ff944fc2d
commit 2cc5794428
3 changed files with 39 additions and 27 deletions

View file

@ -30,6 +30,7 @@ import org.apache.http.entity.ByteArrayEntity;
import com.raytheon.uf.common.comm.HttpClient;
import com.raytheon.uf.common.comm.HttpClient.HttpClientResponse;
import com.raytheon.uf.common.comm.NetworkStatistics;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.serialization.SerializationUtil;
import com.raytheon.uf.common.serialization.annotations.DynamicSerialize;
@ -68,6 +69,9 @@ public class CollaborationObjectEventStorage implements
private static final int SESSION_DATA_PORT = 80;
private static NetworkStatistics stats = com.raytheon.uf.viz.collaboration.Activator
.getDefault().getNetworkStats();
public static IObjectEventPersistance createPersistanceObject(
ISharedDisplaySession session) throws CollaborationException {
CollaborationObjectEventStorage persistance = new CollaborationObjectEventStorage(
@ -134,8 +138,10 @@ public class CollaborationObjectEventStorage implements
+ event.getClass().getName() + ".obj";
HttpPut put = new HttpPut(eventObjectURL);
put.setEntity(new ByteArrayEntity(Tools.compress(SerializationUtil
.transformToThrift(event))));
byte[] toPersist = Tools.compress(SerializationUtil
.transformToThrift(event));
stats.log(event.getClass().getSimpleName(), toPersist.length, 0);
put.setEntity(new ByteArrayEntity(toPersist));
HttpClientResponse response = executeRequest(put);
if (isSuccess(response.code) == false) {
throw new CollaborationException(
@ -182,6 +188,8 @@ public class CollaborationObjectEventStorage implements
HttpClientResponse response = executeRequest(get);
if (isSuccess(response.code)) {
try {
stats.log(event.getClass().getSimpleName(), 0,
response.data.length);
return (AbstractDispatchingObjectEvent) SerializationUtil
.transformFromThrift(Tools
.uncompress(response.data));

View file

@ -82,15 +82,18 @@ public class StatsJob extends Job {
- lastRequestCount;
System.out.println("Last minute sent " + requestCountInLastMinute
+ " messages for a total of " + (sentInLastMinute / 1000)
+ " kB sent and " + (receivedInLastMinute / 1000)
+ " kB received");
+ " messages for a total of "
+ NetworkStatistics.toString(sentInLastMinute)
+ " sent and "
+ NetworkStatistics.toString(receivedInLastMinute)
+ " received");
lastSent = total.getBytesSent();
lastReceived = total.getBytesReceived();
lastRequestCount = total.getRequestCount();
System.out.println("Total sent " + total.getRequestCount()
+ " messages for a total of " + (lastSent / 1000)
+ " kB sent and " + (lastReceived / 1000) + " kB received");
+ " messages for a total of "
+ NetworkStatistics.toString(lastSent) + " sent and "
+ NetworkStatistics.toString(lastReceived) + " received");
NetworkTraffic[] mapped = stats.getMappedTrafficStats();
for (NetworkTraffic nt : mapped) {
System.out.println(nt);

View file

@ -106,32 +106,14 @@ public class NetworkStatistics {
*/
@Override
public String toString() {
String sentString = toString(bytesSent), receivedString = toString(bytesReceived);
String sentString = NetworkStatistics.toString(bytesSent), receivedString = NetworkStatistics
.toString(bytesReceived);
return "Network Traffic Stats for '" + identifier + "' : "
+ requestCount + " messages, sent " + sentString
+ ", received " + receivedString;
}
private static final long[] divisions = new long[] { 1, 1024,
1024 * 1024, 1024 * 1024 * 1024 };
private static final String[] units = new String[] { "B", "kB", "MB",
"GB" };
private String toString(long amount) {
String unit = units[units.length - 1];
long divideBy = divisions[divisions.length - 1];
for (int i = 0; i < divisions.length - 1; ++i) {
if (amount < divisions[i + 1]) {
divideBy = divisions[i];
unit = units[i];
break;
}
}
return ((amount / divideBy) + unit);
}
}
private NetworkTraffic totalTraffic = new NetworkTraffic(null);
@ -208,4 +190,23 @@ public class NetworkStatistics {
}
return traffic;
}
private static final long[] divisions = new long[] { 1, 1024, 1024 * 1024,
1024 * 1024 * 1024 };
private static final String[] units = new String[] { "B", "kB", "MB", "GB" };
public static String toString(long amount) {
String unit = units[units.length - 1];
long divideBy = divisions[divisions.length - 1];
for (int i = 0; i < divisions.length - 1; ++i) {
if (amount < divisions[i + 1]) {
divideBy = divisions[i];
unit = units[i];
break;
}
}
return ((amount / divideBy) + unit);
}
}