Implement query about total data volume per minute

This commit is contained in:
Jan Philipp Timme 2016-12-12 13:35:00 +01:00
parent 4f46226ba9
commit 19b6fc3e4e
Signed by untrusted user: JPT
GPG Key ID: 5F2C85EC6F3754B7
3 changed files with 28 additions and 7 deletions

View File

@ -25,6 +25,9 @@ public class Main {
for(TcpConnectionModel m : result) {
System.out.println(m.toString());
}
long r = tcr.getTotalDataVolumePerMinuteBetweenHosts("172.16.114.207", "206.251.19.72");
System.out.println("Bytes per Second: " + r);
// Done
odhs.close();

View File

@ -101,6 +101,10 @@ public class TcpConnectionModel {
sb.append(this.startTs);
sb.append(".");
sb.append(this.startMs);
sb.append("->");
sb.append(this.endTs);
sb.append(".");
sb.append(this.endMs);
sb.append("] ");
sb.append(this.sourceIp);
sb.append(":");

View File

@ -3,9 +3,7 @@ package de.hsh.inform.orientdb_project.repository;
import java.util.ArrayList;
import java.util.List;
import com.orientechnologies.orient.core.command.OCommandRequest;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.tinkerpop.blueprints.GraphQuery;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
@ -46,11 +44,27 @@ public class TcpConnectionRepository {
return this.getListFromVertices(vertices);
}
public List<TcpConnectionModel> getTotalDataVolumeBetweenHosts(String ipA, String ipB) {
GraphQuery gq = this.ogf.query();
gq = gq.has("@class", "TcpConnection");
// TODO
return this.getListFromVertices(gq.vertices());
public long getTotalDataVolumePerMinuteBetweenHosts(String ipA, String ipB) {
String sql = "SELECT FROM TcpConnection "
+ "WHERE (sourceIp = '" + ipA + "' AND targetIp = '" + ipB + "') "
+ "OR (sourceIp = '" + ipB + "' AND targetIp = '" + ipA + "') ";
@SuppressWarnings("unchecked") // We know.
Iterable<Vertex> vertices = (Iterable<Vertex>) this.ogf.command(new OCommandSQL(sql)).execute();
List<TcpConnectionModel> result = this.getListFromVertices(vertices);
long earliestStartTs = -1;
long latestEndTs = -1;
long totalVolume = 0;
for(TcpConnectionModel model : result) {
System.out.println(model.toString());
totalVolume += model.getTotalVolume();
if(earliestStartTs == -1 || earliestStartTs > model.startTs) {
earliestStartTs = model.startTs;
}
if(latestEndTs == -1 || latestEndTs < model.endTs) {
latestEndTs = model.endTs;
}
}
return (long) ((1.0*totalVolume) / (1.0*(latestEndTs - earliestStartTs)));
}
private List<TcpConnectionModel> getListFromVertices(Iterable<Vertex> vertices) {