use of org.hyperic.sigar.Tcp in project graylog2-server by Graylog2.
the class SigarNetworkProbe method networkStats.
@Override
public synchronized NetworkStats networkStats() {
final Sigar sigar = sigarService.sigar();
String primaryInterface;
try {
final NetInterfaceConfig netInterfaceConfig = sigar.getNetInterfaceConfig(null);
primaryInterface = netInterfaceConfig.getName();
} catch (SigarException e) {
primaryInterface = null;
}
final Map<String, NetworkStats.Interface> interfaces = new HashMap<>();
try {
final String[] netInterfaceList = firstNonNull(sigar.getNetInterfaceList(), new String[0]);
for (String interfaceName : netInterfaceList) {
final NetInterfaceStat netInterfaceStat = sigar.getNetInterfaceStat(interfaceName);
final NetworkStats.InterfaceStats interfaceStats = NetworkStats.InterfaceStats.create(netInterfaceStat.getRxPackets(), netInterfaceStat.getRxErrors(), netInterfaceStat.getRxDropped(), netInterfaceStat.getRxOverruns(), netInterfaceStat.getRxFrame(), netInterfaceStat.getTxPackets(), netInterfaceStat.getTxErrors(), netInterfaceStat.getTxDropped(), netInterfaceStat.getTxOverruns(), netInterfaceStat.getTxCarrier(), netInterfaceStat.getTxCollisions(), netInterfaceStat.getRxBytes(), netInterfaceStat.getTxBytes());
final NetInterfaceConfig netInterfaceConfig = sigar.getNetInterfaceConfig(interfaceName);
final NetworkStats.Interface networkInterface = NetworkStats.Interface.create(netInterfaceConfig.getName(), Collections.singleton(netInterfaceConfig.getAddress()), netInterfaceConfig.getHwaddr(), netInterfaceConfig.getMtu(), interfaceStats);
interfaces.put(interfaceName, networkInterface);
}
} catch (SigarException e) {
// ignore
}
NetworkStats.TcpStats tcpStats;
try {
final Tcp tcp = sigar.getTcp();
tcpStats = NetworkStats.TcpStats.create(tcp.getActiveOpens(), tcp.getPassiveOpens(), tcp.getAttemptFails(), tcp.getEstabResets(), tcp.getCurrEstab(), tcp.getInSegs(), tcp.getOutSegs(), tcp.getRetransSegs(), tcp.getInErrs(), tcp.getOutRsts());
} catch (SigarException e) {
tcpStats = null;
}
return NetworkStats.create(primaryInterface, interfaces, tcpStats);
}
Aggregations