add totals for num in/out connections
This commit is contained in:
parent
1d6f2ff235
commit
1c0de9075a
|
@ -10,7 +10,8 @@ public class NetPortMap {
|
||||||
private Map inbound;
|
private Map inbound;
|
||||||
private Map outbound;
|
private Map outbound;
|
||||||
private int[] states;
|
private int[] states;
|
||||||
|
private int inboundTotal, outboundTotal;
|
||||||
|
|
||||||
public NetPortMap() {
|
public NetPortMap() {
|
||||||
this.sigar = new Sigar();
|
this.sigar = new Sigar();
|
||||||
}
|
}
|
||||||
|
@ -37,6 +38,7 @@ public class NetPortMap {
|
||||||
public void stat(int flags) throws SigarException {
|
public void stat(int flags) throws SigarException {
|
||||||
this.inbound = new HashMap();
|
this.inbound = new HashMap();
|
||||||
this.outbound = new HashMap();
|
this.outbound = new HashMap();
|
||||||
|
this.inboundTotal = this.outboundTotal = 0;
|
||||||
this.states = new int[NetFlags.TCP_UNKNOWN];
|
this.states = new int[NetFlags.TCP_UNKNOWN];
|
||||||
for (int i=0; i<this.states.length; i++) {
|
for (int i=0; i<this.states.length; i++) {
|
||||||
this.states[i] = 0;
|
this.states[i] = 0;
|
||||||
|
@ -77,6 +79,7 @@ public class NetPortMap {
|
||||||
String ip = conn.getRemoteAddress();
|
String ip = conn.getRemoteAddress();
|
||||||
|
|
||||||
if (addresses == null) {
|
if (addresses == null) {
|
||||||
|
this.outboundTotal++;
|
||||||
ip = conn.getRemoteAddress();
|
ip = conn.getRemoteAddress();
|
||||||
port = new Long(conn.getRemotePort());
|
port = new Long(conn.getRemotePort());
|
||||||
addresses = (Map)this.outbound.get(port);
|
addresses = (Map)this.outbound.get(port);
|
||||||
|
@ -85,6 +88,9 @@ public class NetPortMap {
|
||||||
this.outbound.put(port, addresses);
|
this.outbound.put(port, addresses);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
this.inboundTotal++;
|
||||||
|
}
|
||||||
|
|
||||||
IpEntry entry = (IpEntry)addresses.get(ip);
|
IpEntry entry = (IpEntry)addresses.get(ip);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
|
@ -108,6 +114,14 @@ public class NetPortMap {
|
||||||
return this.outbound;
|
return this.outbound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getInboundConnectionsTotal() {
|
||||||
|
return this.inboundTotal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOutboundConnectionsTotal() {
|
||||||
|
return this.outboundTotal;
|
||||||
|
}
|
||||||
|
|
||||||
public int[] getStates() {
|
public int[] getStates() {
|
||||||
return this.states;
|
return this.states;
|
||||||
}
|
}
|
||||||
|
@ -127,10 +141,12 @@ public class NetPortMap {
|
||||||
NetPortMap map = new NetPortMap();
|
NetPortMap map = new NetPortMap();
|
||||||
map.stat();
|
map.stat();
|
||||||
|
|
||||||
System.out.println("Inbound Connections...");
|
System.out.println(map.inboundTotal +
|
||||||
|
" Inbound Connections...");
|
||||||
dumpConnections(map.getInboundConnections());
|
dumpConnections(map.getInboundConnections());
|
||||||
|
|
||||||
System.out.println("\nOutbound Connections...");
|
System.out.println("\n" + map.outboundTotal +
|
||||||
|
" Outbound Connections...");
|
||||||
dumpConnections(map.getOutboundConnections());
|
dumpConnections(map.getOutboundConnections());
|
||||||
|
|
||||||
System.out.println("\nStates...");
|
System.out.println("\nStates...");
|
||||||
|
|
Loading…
Reference in New Issue